001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.procedure2; 019 020import java.io.IOException; 021import java.util.concurrent.CountDownLatch; 022import org.apache.hadoop.hbase.HBaseCommonTestingUtil; 023import org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility.NoopProcedure; 024import org.apache.hadoop.hbase.procedure2.store.wal.WALProcedureStore; 025import org.apache.hadoop.hbase.testclassification.MasterTests; 026import org.apache.hadoop.hbase.testclassification.MediumTests; 027import org.junit.jupiter.api.AfterAll; 028import org.junit.jupiter.api.AfterEach; 029import org.junit.jupiter.api.BeforeEach; 030import org.junit.jupiter.api.Tag; 031import org.junit.jupiter.api.Test; 032import org.junit.jupiter.api.TestInfo; 033 034/** 035 * Testcase for HBASE-20973 036 */ 037@Tag(MasterTests.TAG) 038@Tag(MediumTests.TAG) 039public class TestProcedureRollbackAIOOB { 040 041 private static final HBaseCommonTestingUtil UTIL = new HBaseCommonTestingUtil(); 042 043 public static final class ParentProcedure extends NoopProcedure<Void> { 044 045 private final CountDownLatch latch = new CountDownLatch(1); 046 047 private boolean scheduled; 048 049 @Override 050 protected Procedure<Void>[] execute(Void env) 051 throws ProcedureYieldException, ProcedureSuspendedException, InterruptedException { 052 latch.await(); 053 if (scheduled) { 054 return null; 055 } 056 scheduled = true; 057 return new Procedure[] { new SubProcedure() }; 058 } 059 } 060 061 public static final class SubProcedure extends NoopProcedure<Void> { 062 063 @Override 064 protected Procedure[] execute(Void env) 065 throws ProcedureYieldException, ProcedureSuspendedException, InterruptedException { 066 setFailure("Inject error", new RuntimeException("Inject error")); 067 return null; 068 } 069 } 070 071 private WALProcedureStore procStore; 072 073 private ProcedureExecutor<Void> procExec; 074 075 @BeforeEach 076 public void setUp(TestInfo testInfo) throws IOException { 077 procStore = ProcedureTestingUtility.createWalStore(UTIL.getConfiguration(), 078 UTIL.getDataTestDir(testInfo.getTestMethod().get().getName())); 079 procStore.start(2); 080 procExec = new ProcedureExecutor<>(UTIL.getConfiguration(), null, procStore); 081 ProcedureTestingUtility.initAndStartWorkers(procExec, 2, true); 082 } 083 084 @AfterEach 085 public void tearDown() { 086 procExec.stop(); 087 procStore.stop(false); 088 } 089 090 @AfterAll 091 public static void tearDownAfterClass() throws IOException { 092 UTIL.cleanupTestDir(); 093 } 094 095 @Test 096 public void testArrayIndexOutOfBounds() { 097 ParentProcedure proc = new ParentProcedure(); 098 long procId = procExec.submitProcedure(proc); 099 long noopProcId = -1L; 100 // make sure that the sub procedure will have a new BitSetNode 101 for (int i = 0; i < Long.SIZE - 2; i++) { 102 noopProcId = procExec.submitProcedure(new NoopProcedure<>()); 103 } 104 final long lastNoopProcId = noopProcId; 105 UTIL.waitFor(30000, () -> procExec.isFinished(lastNoopProcId)); 106 proc.latch.countDown(); 107 UTIL.waitFor(10000, () -> procExec.isFinished(procId)); 108 } 109}