http://git-wip-us.apache.org/repos/asf/hbase-site/blob/323b17d9/testdevapidocs/src-html/org/apache/hadoop/hbase/procedure2/ProcedureTestingUtility.LoadCounter.html ---------------------------------------------------------------------- diff --git a/testdevapidocs/src-html/org/apache/hadoop/hbase/procedure2/ProcedureTestingUtility.LoadCounter.html b/testdevapidocs/src-html/org/apache/hadoop/hbase/procedure2/ProcedureTestingUtility.LoadCounter.html index edb675e..eb90a1f 100644 --- a/testdevapidocs/src-html/org/apache/hadoop/hbase/procedure2/ProcedureTestingUtility.LoadCounter.html +++ b/testdevapidocs/src-html/org/apache/hadoop/hbase/procedure2/ProcedureTestingUtility.LoadCounter.html @@ -408,184 +408,224 @@ <span class="sourceLineNo">400</span> }<a name="line.400"></a> <span class="sourceLineNo">401</span> }<a name="line.401"></a> <span class="sourceLineNo">402</span><a name="line.402"></a> -<span class="sourceLineNo">403</span> public static class TestProcedure extends NoopProcedure<Void> {<a name="line.403"></a> -<span class="sourceLineNo">404</span> private byte[] data = null;<a name="line.404"></a> -<span class="sourceLineNo">405</span><a name="line.405"></a> -<span class="sourceLineNo">406</span> public TestProcedure() {}<a name="line.406"></a> +<span class="sourceLineNo">403</span> public static class NoopStateMachineProcedure<TEnv, TState><a name="line.403"></a> +<span class="sourceLineNo">404</span> extends StateMachineProcedure<TEnv, TState> {<a name="line.404"></a> +<span class="sourceLineNo">405</span> private TState initialState;<a name="line.405"></a> +<span class="sourceLineNo">406</span> private TEnv env;<a name="line.406"></a> <span class="sourceLineNo">407</span><a name="line.407"></a> -<span class="sourceLineNo">408</span> public TestProcedure(long procId) {<a name="line.408"></a> -<span class="sourceLineNo">409</span> this(procId, 0);<a name="line.409"></a> -<span class="sourceLineNo">410</span> }<a name="line.410"></a> -<span class="sourceLineNo">411</span><a name="line.411"></a> -<span class="sourceLineNo">412</span> public TestProcedure(long procId, long parentId) {<a name="line.412"></a> -<span class="sourceLineNo">413</span> this(procId, parentId, null);<a name="line.413"></a> +<span class="sourceLineNo">408</span> public NoopStateMachineProcedure() {<a name="line.408"></a> +<span class="sourceLineNo">409</span> }<a name="line.409"></a> +<span class="sourceLineNo">410</span><a name="line.410"></a> +<span class="sourceLineNo">411</span> public NoopStateMachineProcedure(TEnv env, TState initialState) {<a name="line.411"></a> +<span class="sourceLineNo">412</span> this.env = env;<a name="line.412"></a> +<span class="sourceLineNo">413</span> this.initialState = initialState;<a name="line.413"></a> <span class="sourceLineNo">414</span> }<a name="line.414"></a> <span class="sourceLineNo">415</span><a name="line.415"></a> -<span class="sourceLineNo">416</span> public TestProcedure(long procId, long parentId, byte[] data) {<a name="line.416"></a> -<span class="sourceLineNo">417</span> this(procId, parentId, parentId, data);<a name="line.417"></a> -<span class="sourceLineNo">418</span> }<a name="line.418"></a> -<span class="sourceLineNo">419</span><a name="line.419"></a> -<span class="sourceLineNo">420</span> public TestProcedure(long procId, long parentId, long rootId, byte[] data) {<a name="line.420"></a> -<span class="sourceLineNo">421</span> setData(data);<a name="line.421"></a> -<span class="sourceLineNo">422</span> setProcId(procId);<a name="line.422"></a> -<span class="sourceLineNo">423</span> if (parentId > 0) {<a name="line.423"></a> -<span class="sourceLineNo">424</span> setParentProcId(parentId);<a name="line.424"></a> -<span class="sourceLineNo">425</span> }<a name="line.425"></a> -<span class="sourceLineNo">426</span> if (rootId > 0 || parentId > 0) {<a name="line.426"></a> -<span class="sourceLineNo">427</span> setRootProcId(rootId);<a name="line.427"></a> -<span class="sourceLineNo">428</span> }<a name="line.428"></a> -<span class="sourceLineNo">429</span> }<a name="line.429"></a> -<span class="sourceLineNo">430</span><a name="line.430"></a> -<span class="sourceLineNo">431</span> public void addStackId(final int index) {<a name="line.431"></a> -<span class="sourceLineNo">432</span> addStackIndex(index);<a name="line.432"></a> -<span class="sourceLineNo">433</span> }<a name="line.433"></a> -<span class="sourceLineNo">434</span><a name="line.434"></a> -<span class="sourceLineNo">435</span> public void setSuccessState() {<a name="line.435"></a> -<span class="sourceLineNo">436</span> setState(ProcedureState.SUCCESS);<a name="line.436"></a> -<span class="sourceLineNo">437</span> }<a name="line.437"></a> -<span class="sourceLineNo">438</span><a name="line.438"></a> -<span class="sourceLineNo">439</span> public void setData(final byte[] data) {<a name="line.439"></a> -<span class="sourceLineNo">440</span> this.data = data;<a name="line.440"></a> -<span class="sourceLineNo">441</span> }<a name="line.441"></a> +<span class="sourceLineNo">416</span> @Override<a name="line.416"></a> +<span class="sourceLineNo">417</span> protected Flow executeFromState(TEnv env, TState tState)<a name="line.417"></a> +<span class="sourceLineNo">418</span> throws ProcedureSuspendedException, ProcedureYieldException, InterruptedException {<a name="line.418"></a> +<span class="sourceLineNo">419</span> return null;<a name="line.419"></a> +<span class="sourceLineNo">420</span> }<a name="line.420"></a> +<span class="sourceLineNo">421</span><a name="line.421"></a> +<span class="sourceLineNo">422</span> @Override<a name="line.422"></a> +<span class="sourceLineNo">423</span> protected void rollbackState(TEnv env, TState tState) throws IOException, InterruptedException {<a name="line.423"></a> +<span class="sourceLineNo">424</span><a name="line.424"></a> +<span class="sourceLineNo">425</span> }<a name="line.425"></a> +<span class="sourceLineNo">426</span><a name="line.426"></a> +<span class="sourceLineNo">427</span> @Override<a name="line.427"></a> +<span class="sourceLineNo">428</span> protected TState getState(int stateId) {<a name="line.428"></a> +<span class="sourceLineNo">429</span> return null;<a name="line.429"></a> +<span class="sourceLineNo">430</span> }<a name="line.430"></a> +<span class="sourceLineNo">431</span><a name="line.431"></a> +<span class="sourceLineNo">432</span> @Override<a name="line.432"></a> +<span class="sourceLineNo">433</span> protected int getStateId(TState tState) {<a name="line.433"></a> +<span class="sourceLineNo">434</span> return 0;<a name="line.434"></a> +<span class="sourceLineNo">435</span> }<a name="line.435"></a> +<span class="sourceLineNo">436</span><a name="line.436"></a> +<span class="sourceLineNo">437</span> @Override<a name="line.437"></a> +<span class="sourceLineNo">438</span> protected TState getInitialState() {<a name="line.438"></a> +<span class="sourceLineNo">439</span> return initialState;<a name="line.439"></a> +<span class="sourceLineNo">440</span> }<a name="line.440"></a> +<span class="sourceLineNo">441</span> }<a name="line.441"></a> <span class="sourceLineNo">442</span><a name="line.442"></a> -<span class="sourceLineNo">443</span> @Override<a name="line.443"></a> -<span class="sourceLineNo">444</span> protected void serializeStateData(ProcedureStateSerializer serializer)<a name="line.444"></a> -<span class="sourceLineNo">445</span> throws IOException {<a name="line.445"></a> -<span class="sourceLineNo">446</span> ByteString dataString = ByteString.copyFrom((data == null) ? new byte[0] : data);<a name="line.446"></a> -<span class="sourceLineNo">447</span> BytesValue.Builder builder = BytesValue.newBuilder().setValue(dataString);<a name="line.447"></a> -<span class="sourceLineNo">448</span> serializer.serialize(builder.build());<a name="line.448"></a> -<span class="sourceLineNo">449</span> }<a name="line.449"></a> -<span class="sourceLineNo">450</span><a name="line.450"></a> -<span class="sourceLineNo">451</span> @Override<a name="line.451"></a> -<span class="sourceLineNo">452</span> protected void deserializeStateData(ProcedureStateSerializer serializer)<a name="line.452"></a> -<span class="sourceLineNo">453</span> throws IOException {<a name="line.453"></a> -<span class="sourceLineNo">454</span> BytesValue bytesValue = serializer.deserialize(BytesValue.class);<a name="line.454"></a> -<span class="sourceLineNo">455</span> ByteString dataString = bytesValue.getValue();<a name="line.455"></a> -<span class="sourceLineNo">456</span><a name="line.456"></a> -<span class="sourceLineNo">457</span> if (dataString.isEmpty()) {<a name="line.457"></a> -<span class="sourceLineNo">458</span> data = null;<a name="line.458"></a> -<span class="sourceLineNo">459</span> } else {<a name="line.459"></a> -<span class="sourceLineNo">460</span> data = dataString.toByteArray();<a name="line.460"></a> -<span class="sourceLineNo">461</span> }<a name="line.461"></a> -<span class="sourceLineNo">462</span> }<a name="line.462"></a> -<span class="sourceLineNo">463</span><a name="line.463"></a> -<span class="sourceLineNo">464</span> // Mark acquire/release lock functions public for test uses.<a name="line.464"></a> -<span class="sourceLineNo">465</span> @Override<a name="line.465"></a> -<span class="sourceLineNo">466</span> public LockState acquireLock(Void env) {<a name="line.466"></a> -<span class="sourceLineNo">467</span> return LockState.LOCK_ACQUIRED;<a name="line.467"></a> -<span class="sourceLineNo">468</span> }<a name="line.468"></a> -<span class="sourceLineNo">469</span><a name="line.469"></a> -<span class="sourceLineNo">470</span> @Override<a name="line.470"></a> -<span class="sourceLineNo">471</span> public void releaseLock(Void env) {<a name="line.471"></a> -<span class="sourceLineNo">472</span> // no-op<a name="line.472"></a> +<span class="sourceLineNo">443</span> public static class TestProcedure extends NoopProcedure<Void> {<a name="line.443"></a> +<span class="sourceLineNo">444</span> private byte[] data = null;<a name="line.444"></a> +<span class="sourceLineNo">445</span><a name="line.445"></a> +<span class="sourceLineNo">446</span> public TestProcedure() {}<a name="line.446"></a> +<span class="sourceLineNo">447</span><a name="line.447"></a> +<span class="sourceLineNo">448</span> public TestProcedure(long procId) {<a name="line.448"></a> +<span class="sourceLineNo">449</span> this(procId, 0);<a name="line.449"></a> +<span class="sourceLineNo">450</span> }<a name="line.450"></a> +<span class="sourceLineNo">451</span><a name="line.451"></a> +<span class="sourceLineNo">452</span> public TestProcedure(long procId, long parentId) {<a name="line.452"></a> +<span class="sourceLineNo">453</span> this(procId, parentId, null);<a name="line.453"></a> +<span class="sourceLineNo">454</span> }<a name="line.454"></a> +<span class="sourceLineNo">455</span><a name="line.455"></a> +<span class="sourceLineNo">456</span> public TestProcedure(long procId, long parentId, byte[] data) {<a name="line.456"></a> +<span class="sourceLineNo">457</span> this(procId, parentId, parentId, data);<a name="line.457"></a> +<span class="sourceLineNo">458</span> }<a name="line.458"></a> +<span class="sourceLineNo">459</span><a name="line.459"></a> +<span class="sourceLineNo">460</span> public TestProcedure(long procId, long parentId, long rootId, byte[] data) {<a name="line.460"></a> +<span class="sourceLineNo">461</span> setData(data);<a name="line.461"></a> +<span class="sourceLineNo">462</span> setProcId(procId);<a name="line.462"></a> +<span class="sourceLineNo">463</span> if (parentId > 0) {<a name="line.463"></a> +<span class="sourceLineNo">464</span> setParentProcId(parentId);<a name="line.464"></a> +<span class="sourceLineNo">465</span> }<a name="line.465"></a> +<span class="sourceLineNo">466</span> if (rootId > 0 || parentId > 0) {<a name="line.466"></a> +<span class="sourceLineNo">467</span> setRootProcId(rootId);<a name="line.467"></a> +<span class="sourceLineNo">468</span> }<a name="line.468"></a> +<span class="sourceLineNo">469</span> }<a name="line.469"></a> +<span class="sourceLineNo">470</span><a name="line.470"></a> +<span class="sourceLineNo">471</span> public void addStackId(final int index) {<a name="line.471"></a> +<span class="sourceLineNo">472</span> addStackIndex(index);<a name="line.472"></a> <span class="sourceLineNo">473</span> }<a name="line.473"></a> -<span class="sourceLineNo">474</span> }<a name="line.474"></a> -<span class="sourceLineNo">475</span><a name="line.475"></a> -<span class="sourceLineNo">476</span> public static class LoadCounter implements ProcedureStore.ProcedureLoader {<a name="line.476"></a> -<span class="sourceLineNo">477</span> private final ArrayList<Procedure> corrupted = new ArrayList<>();<a name="line.477"></a> -<span class="sourceLineNo">478</span> private final ArrayList<Procedure> completed = new ArrayList<>();<a name="line.478"></a> -<span class="sourceLineNo">479</span> private final ArrayList<Procedure> runnable = new ArrayList<>();<a name="line.479"></a> -<span class="sourceLineNo">480</span><a name="line.480"></a> -<span class="sourceLineNo">481</span> private Set<Long> procIds;<a name="line.481"></a> -<span class="sourceLineNo">482</span> private long maxProcId = 0;<a name="line.482"></a> -<span class="sourceLineNo">483</span><a name="line.483"></a> -<span class="sourceLineNo">484</span> public LoadCounter() {<a name="line.484"></a> -<span class="sourceLineNo">485</span> this(null);<a name="line.485"></a> -<span class="sourceLineNo">486</span> }<a name="line.486"></a> -<span class="sourceLineNo">487</span><a name="line.487"></a> -<span class="sourceLineNo">488</span> public LoadCounter(final Set<Long> procIds) {<a name="line.488"></a> -<span class="sourceLineNo">489</span> this.procIds = procIds;<a name="line.489"></a> -<span class="sourceLineNo">490</span> }<a name="line.490"></a> -<span class="sourceLineNo">491</span><a name="line.491"></a> -<span class="sourceLineNo">492</span> public void reset() {<a name="line.492"></a> -<span class="sourceLineNo">493</span> reset(null);<a name="line.493"></a> -<span class="sourceLineNo">494</span> }<a name="line.494"></a> -<span class="sourceLineNo">495</span><a name="line.495"></a> -<span class="sourceLineNo">496</span> public void reset(final Set<Long> procIds) {<a name="line.496"></a> -<span class="sourceLineNo">497</span> corrupted.clear();<a name="line.497"></a> -<span class="sourceLineNo">498</span> completed.clear();<a name="line.498"></a> -<span class="sourceLineNo">499</span> runnable.clear();<a name="line.499"></a> -<span class="sourceLineNo">500</span> this.procIds = procIds;<a name="line.500"></a> -<span class="sourceLineNo">501</span> this.maxProcId = 0;<a name="line.501"></a> +<span class="sourceLineNo">474</span><a name="line.474"></a> +<span class="sourceLineNo">475</span> public void setSuccessState() {<a name="line.475"></a> +<span class="sourceLineNo">476</span> setState(ProcedureState.SUCCESS);<a name="line.476"></a> +<span class="sourceLineNo">477</span> }<a name="line.477"></a> +<span class="sourceLineNo">478</span><a name="line.478"></a> +<span class="sourceLineNo">479</span> public void setData(final byte[] data) {<a name="line.479"></a> +<span class="sourceLineNo">480</span> this.data = data;<a name="line.480"></a> +<span class="sourceLineNo">481</span> }<a name="line.481"></a> +<span class="sourceLineNo">482</span><a name="line.482"></a> +<span class="sourceLineNo">483</span> @Override<a name="line.483"></a> +<span class="sourceLineNo">484</span> protected void serializeStateData(ProcedureStateSerializer serializer)<a name="line.484"></a> +<span class="sourceLineNo">485</span> throws IOException {<a name="line.485"></a> +<span class="sourceLineNo">486</span> ByteString dataString = ByteString.copyFrom((data == null) ? new byte[0] : data);<a name="line.486"></a> +<span class="sourceLineNo">487</span> BytesValue.Builder builder = BytesValue.newBuilder().setValue(dataString);<a name="line.487"></a> +<span class="sourceLineNo">488</span> serializer.serialize(builder.build());<a name="line.488"></a> +<span class="sourceLineNo">489</span> }<a name="line.489"></a> +<span class="sourceLineNo">490</span><a name="line.490"></a> +<span class="sourceLineNo">491</span> @Override<a name="line.491"></a> +<span class="sourceLineNo">492</span> protected void deserializeStateData(ProcedureStateSerializer serializer)<a name="line.492"></a> +<span class="sourceLineNo">493</span> throws IOException {<a name="line.493"></a> +<span class="sourceLineNo">494</span> BytesValue bytesValue = serializer.deserialize(BytesValue.class);<a name="line.494"></a> +<span class="sourceLineNo">495</span> ByteString dataString = bytesValue.getValue();<a name="line.495"></a> +<span class="sourceLineNo">496</span><a name="line.496"></a> +<span class="sourceLineNo">497</span> if (dataString.isEmpty()) {<a name="line.497"></a> +<span class="sourceLineNo">498</span> data = null;<a name="line.498"></a> +<span class="sourceLineNo">499</span> } else {<a name="line.499"></a> +<span class="sourceLineNo">500</span> data = dataString.toByteArray();<a name="line.500"></a> +<span class="sourceLineNo">501</span> }<a name="line.501"></a> <span class="sourceLineNo">502</span> }<a name="line.502"></a> <span class="sourceLineNo">503</span><a name="line.503"></a> -<span class="sourceLineNo">504</span> public long getMaxProcId() {<a name="line.504"></a> -<span class="sourceLineNo">505</span> return maxProcId;<a name="line.505"></a> -<span class="sourceLineNo">506</span> }<a name="line.506"></a> -<span class="sourceLineNo">507</span><a name="line.507"></a> -<span class="sourceLineNo">508</span> public ArrayList<Procedure> getRunnables() {<a name="line.508"></a> -<span class="sourceLineNo">509</span> return runnable;<a name="line.509"></a> -<span class="sourceLineNo">510</span> }<a name="line.510"></a> -<span class="sourceLineNo">511</span><a name="line.511"></a> -<span class="sourceLineNo">512</span> public int getRunnableCount() {<a name="line.512"></a> -<span class="sourceLineNo">513</span> return runnable.size();<a name="line.513"></a> -<span class="sourceLineNo">514</span> }<a name="line.514"></a> +<span class="sourceLineNo">504</span> // Mark acquire/release lock functions public for test uses.<a name="line.504"></a> +<span class="sourceLineNo">505</span> @Override<a name="line.505"></a> +<span class="sourceLineNo">506</span> public LockState acquireLock(Void env) {<a name="line.506"></a> +<span class="sourceLineNo">507</span> return LockState.LOCK_ACQUIRED;<a name="line.507"></a> +<span class="sourceLineNo">508</span> }<a name="line.508"></a> +<span class="sourceLineNo">509</span><a name="line.509"></a> +<span class="sourceLineNo">510</span> @Override<a name="line.510"></a> +<span class="sourceLineNo">511</span> public void releaseLock(Void env) {<a name="line.511"></a> +<span class="sourceLineNo">512</span> // no-op<a name="line.512"></a> +<span class="sourceLineNo">513</span> }<a name="line.513"></a> +<span class="sourceLineNo">514</span> }<a name="line.514"></a> <span class="sourceLineNo">515</span><a name="line.515"></a> -<span class="sourceLineNo">516</span> public ArrayList<Procedure> getCompleted() {<a name="line.516"></a> -<span class="sourceLineNo">517</span> return completed;<a name="line.517"></a> -<span class="sourceLineNo">518</span> }<a name="line.518"></a> -<span class="sourceLineNo">519</span><a name="line.519"></a> -<span class="sourceLineNo">520</span> public int getCompletedCount() {<a name="line.520"></a> -<span class="sourceLineNo">521</span> return completed.size();<a name="line.521"></a> -<span class="sourceLineNo">522</span> }<a name="line.522"></a> +<span class="sourceLineNo">516</span> public static class LoadCounter implements ProcedureStore.ProcedureLoader {<a name="line.516"></a> +<span class="sourceLineNo">517</span> private final ArrayList<Procedure> corrupted = new ArrayList<>();<a name="line.517"></a> +<span class="sourceLineNo">518</span> private final ArrayList<Procedure> completed = new ArrayList<>();<a name="line.518"></a> +<span class="sourceLineNo">519</span> private final ArrayList<Procedure> runnable = new ArrayList<>();<a name="line.519"></a> +<span class="sourceLineNo">520</span><a name="line.520"></a> +<span class="sourceLineNo">521</span> private Set<Long> procIds;<a name="line.521"></a> +<span class="sourceLineNo">522</span> private long maxProcId = 0;<a name="line.522"></a> <span class="sourceLineNo">523</span><a name="line.523"></a> -<span class="sourceLineNo">524</span> public int getLoadedCount() {<a name="line.524"></a> -<span class="sourceLineNo">525</span> return runnable.size() + completed.size();<a name="line.525"></a> +<span class="sourceLineNo">524</span> public LoadCounter() {<a name="line.524"></a> +<span class="sourceLineNo">525</span> this(null);<a name="line.525"></a> <span class="sourceLineNo">526</span> }<a name="line.526"></a> <span class="sourceLineNo">527</span><a name="line.527"></a> -<span class="sourceLineNo">528</span> public ArrayList<Procedure> getCorrupted() {<a name="line.528"></a> -<span class="sourceLineNo">529</span> return corrupted;<a name="line.529"></a> +<span class="sourceLineNo">528</span> public LoadCounter(final Set<Long> procIds) {<a name="line.528"></a> +<span class="sourceLineNo">529</span> this.procIds = procIds;<a name="line.529"></a> <span class="sourceLineNo">530</span> }<a name="line.530"></a> <span class="sourceLineNo">531</span><a name="line.531"></a> -<span class="sourceLineNo">532</span> public int getCorruptedCount() {<a name="line.532"></a> -<span class="sourceLineNo">533</span> return corrupted.size();<a name="line.533"></a> +<span class="sourceLineNo">532</span> public void reset() {<a name="line.532"></a> +<span class="sourceLineNo">533</span> reset(null);<a name="line.533"></a> <span class="sourceLineNo">534</span> }<a name="line.534"></a> <span class="sourceLineNo">535</span><a name="line.535"></a> -<span class="sourceLineNo">536</span> public boolean isRunnable(final long procId) {<a name="line.536"></a> -<span class="sourceLineNo">537</span> for (Procedure proc: runnable) {<a name="line.537"></a> -<span class="sourceLineNo">538</span> if (proc.getProcId() == procId) {<a name="line.538"></a> -<span class="sourceLineNo">539</span> return true;<a name="line.539"></a> -<span class="sourceLineNo">540</span> }<a name="line.540"></a> -<span class="sourceLineNo">541</span> }<a name="line.541"></a> -<span class="sourceLineNo">542</span> return false;<a name="line.542"></a> -<span class="sourceLineNo">543</span> }<a name="line.543"></a> -<span class="sourceLineNo">544</span><a name="line.544"></a> -<span class="sourceLineNo">545</span> @Override<a name="line.545"></a> -<span class="sourceLineNo">546</span> public void setMaxProcId(long maxProcId) {<a name="line.546"></a> -<span class="sourceLineNo">547</span> this.maxProcId = maxProcId;<a name="line.547"></a> -<span class="sourceLineNo">548</span> }<a name="line.548"></a> -<span class="sourceLineNo">549</span><a name="line.549"></a> -<span class="sourceLineNo">550</span> @Override<a name="line.550"></a> -<span class="sourceLineNo">551</span> public void load(ProcedureIterator procIter) throws IOException {<a name="line.551"></a> -<span class="sourceLineNo">552</span> while (procIter.hasNext()) {<a name="line.552"></a> -<span class="sourceLineNo">553</span> long procId;<a name="line.553"></a> -<span class="sourceLineNo">554</span> if (procIter.isNextFinished()) {<a name="line.554"></a> -<span class="sourceLineNo">555</span> Procedure<?> proc = procIter.next();<a name="line.555"></a> -<span class="sourceLineNo">556</span> procId = proc.getProcId();<a name="line.556"></a> -<span class="sourceLineNo">557</span> LOG.debug("loading completed procId=" + procId + ": " + proc);<a name="line.557"></a> -<span class="sourceLineNo">558</span> completed.add(proc);<a name="line.558"></a> -<span class="sourceLineNo">559</span> } else {<a name="line.559"></a> -<span class="sourceLineNo">560</span> Procedure proc = procIter.next();<a name="line.560"></a> -<span class="sourceLineNo">561</span> procId = proc.getProcId();<a name="line.561"></a> -<span class="sourceLineNo">562</span> LOG.debug("loading runnable procId=" + procId + ": " + proc);<a name="line.562"></a> -<span class="sourceLineNo">563</span> runnable.add(proc);<a name="line.563"></a> -<span class="sourceLineNo">564</span> }<a name="line.564"></a> -<span class="sourceLineNo">565</span> if (procIds != null) {<a name="line.565"></a> -<span class="sourceLineNo">566</span> assertTrue("procId=" + procId + " unexpected", procIds.contains(procId));<a name="line.566"></a> -<span class="sourceLineNo">567</span> }<a name="line.567"></a> -<span class="sourceLineNo">568</span> }<a name="line.568"></a> -<span class="sourceLineNo">569</span> }<a name="line.569"></a> -<span class="sourceLineNo">570</span><a name="line.570"></a> -<span class="sourceLineNo">571</span> @Override<a name="line.571"></a> -<span class="sourceLineNo">572</span> public void handleCorrupted(ProcedureIterator procIter) throws IOException {<a name="line.572"></a> -<span class="sourceLineNo">573</span> while (procIter.hasNext()) {<a name="line.573"></a> -<span class="sourceLineNo">574</span> Procedure proc = procIter.next();<a name="line.574"></a> -<span class="sourceLineNo">575</span> LOG.debug("corrupted procId=" + proc.getProcId() + ": " + proc);<a name="line.575"></a> -<span class="sourceLineNo">576</span> corrupted.add(proc);<a name="line.576"></a> -<span class="sourceLineNo">577</span> }<a name="line.577"></a> -<span class="sourceLineNo">578</span> }<a name="line.578"></a> -<span class="sourceLineNo">579</span> }<a name="line.579"></a> -<span class="sourceLineNo">580</span>}<a name="line.580"></a> +<span class="sourceLineNo">536</span> public void reset(final Set<Long> procIds) {<a name="line.536"></a> +<span class="sourceLineNo">537</span> corrupted.clear();<a name="line.537"></a> +<span class="sourceLineNo">538</span> completed.clear();<a name="line.538"></a> +<span class="sourceLineNo">539</span> runnable.clear();<a name="line.539"></a> +<span class="sourceLineNo">540</span> this.procIds = procIds;<a name="line.540"></a> +<span class="sourceLineNo">541</span> this.maxProcId = 0;<a name="line.541"></a> +<span class="sourceLineNo">542</span> }<a name="line.542"></a> +<span class="sourceLineNo">543</span><a name="line.543"></a> +<span class="sourceLineNo">544</span> public long getMaxProcId() {<a name="line.544"></a> +<span class="sourceLineNo">545</span> return maxProcId;<a name="line.545"></a> +<span class="sourceLineNo">546</span> }<a name="line.546"></a> +<span class="sourceLineNo">547</span><a name="line.547"></a> +<span class="sourceLineNo">548</span> public ArrayList<Procedure> getRunnables() {<a name="line.548"></a> +<span class="sourceLineNo">549</span> return runnable;<a name="line.549"></a> +<span class="sourceLineNo">550</span> }<a name="line.550"></a> +<span class="sourceLineNo">551</span><a name="line.551"></a> +<span class="sourceLineNo">552</span> public int getRunnableCount() {<a name="line.552"></a> +<span class="sourceLineNo">553</span> return runnable.size();<a name="line.553"></a> +<span class="sourceLineNo">554</span> }<a name="line.554"></a> +<span class="sourceLineNo">555</span><a name="line.555"></a> +<span class="sourceLineNo">556</span> public ArrayList<Procedure> getCompleted() {<a name="line.556"></a> +<span class="sourceLineNo">557</span> return completed;<a name="line.557"></a> +<span class="sourceLineNo">558</span> }<a name="line.558"></a> +<span class="sourceLineNo">559</span><a name="line.559"></a> +<span class="sourceLineNo">560</span> public int getCompletedCount() {<a name="line.560"></a> +<span class="sourceLineNo">561</span> return completed.size();<a name="line.561"></a> +<span class="sourceLineNo">562</span> }<a name="line.562"></a> +<span class="sourceLineNo">563</span><a name="line.563"></a> +<span class="sourceLineNo">564</span> public int getLoadedCount() {<a name="line.564"></a> +<span class="sourceLineNo">565</span> return runnable.size() + completed.size();<a name="line.565"></a> +<span class="sourceLineNo">566</span> }<a name="line.566"></a> +<span class="sourceLineNo">567</span><a name="line.567"></a> +<span class="sourceLineNo">568</span> public ArrayList<Procedure> getCorrupted() {<a name="line.568"></a> +<span class="sourceLineNo">569</span> return corrupted;<a name="line.569"></a> +<span class="sourceLineNo">570</span> }<a name="line.570"></a> +<span class="sourceLineNo">571</span><a name="line.571"></a> +<span class="sourceLineNo">572</span> public int getCorruptedCount() {<a name="line.572"></a> +<span class="sourceLineNo">573</span> return corrupted.size();<a name="line.573"></a> +<span class="sourceLineNo">574</span> }<a name="line.574"></a> +<span class="sourceLineNo">575</span><a name="line.575"></a> +<span class="sourceLineNo">576</span> public boolean isRunnable(final long procId) {<a name="line.576"></a> +<span class="sourceLineNo">577</span> for (Procedure proc: runnable) {<a name="line.577"></a> +<span class="sourceLineNo">578</span> if (proc.getProcId() == procId) {<a name="line.578"></a> +<span class="sourceLineNo">579</span> return true;<a name="line.579"></a> +<span class="sourceLineNo">580</span> }<a name="line.580"></a> +<span class="sourceLineNo">581</span> }<a name="line.581"></a> +<span class="sourceLineNo">582</span> return false;<a name="line.582"></a> +<span class="sourceLineNo">583</span> }<a name="line.583"></a> +<span class="sourceLineNo">584</span><a name="line.584"></a> +<span class="sourceLineNo">585</span> @Override<a name="line.585"></a> +<span class="sourceLineNo">586</span> public void setMaxProcId(long maxProcId) {<a name="line.586"></a> +<span class="sourceLineNo">587</span> this.maxProcId = maxProcId;<a name="line.587"></a> +<span class="sourceLineNo">588</span> }<a name="line.588"></a> +<span class="sourceLineNo">589</span><a name="line.589"></a> +<span class="sourceLineNo">590</span> @Override<a name="line.590"></a> +<span class="sourceLineNo">591</span> public void load(ProcedureIterator procIter) throws IOException {<a name="line.591"></a> +<span class="sourceLineNo">592</span> while (procIter.hasNext()) {<a name="line.592"></a> +<span class="sourceLineNo">593</span> long procId;<a name="line.593"></a> +<span class="sourceLineNo">594</span> if (procIter.isNextFinished()) {<a name="line.594"></a> +<span class="sourceLineNo">595</span> Procedure<?> proc = procIter.next();<a name="line.595"></a> +<span class="sourceLineNo">596</span> procId = proc.getProcId();<a name="line.596"></a> +<span class="sourceLineNo">597</span> LOG.debug("loading completed procId=" + procId + ": " + proc);<a name="line.597"></a> +<span class="sourceLineNo">598</span> completed.add(proc);<a name="line.598"></a> +<span class="sourceLineNo">599</span> } else {<a name="line.599"></a> +<span class="sourceLineNo">600</span> Procedure proc = procIter.next();<a name="line.600"></a> +<span class="sourceLineNo">601</span> procId = proc.getProcId();<a name="line.601"></a> +<span class="sourceLineNo">602</span> LOG.debug("loading runnable procId=" + procId + ": " + proc);<a name="line.602"></a> +<span class="sourceLineNo">603</span> runnable.add(proc);<a name="line.603"></a> +<span class="sourceLineNo">604</span> }<a name="line.604"></a> +<span class="sourceLineNo">605</span> if (procIds != null) {<a name="line.605"></a> +<span class="sourceLineNo">606</span> assertTrue("procId=" + procId + " unexpected", procIds.contains(procId));<a name="line.606"></a> +<span class="sourceLineNo">607</span> }<a name="line.607"></a> +<span class="sourceLineNo">608</span> }<a name="line.608"></a> +<span class="sourceLineNo">609</span> }<a name="line.609"></a> +<span class="sourceLineNo">610</span><a name="line.610"></a> +<span class="sourceLineNo">611</span> @Override<a name="line.611"></a> +<span class="sourceLineNo">612</span> public void handleCorrupted(ProcedureIterator procIter) throws IOException {<a name="line.612"></a> +<span class="sourceLineNo">613</span> while (procIter.hasNext()) {<a name="line.613"></a> +<span class="sourceLineNo">614</span> Procedure proc = procIter.next();<a name="line.614"></a> +<span class="sourceLineNo">615</span> LOG.debug("corrupted procId=" + proc.getProcId() + ": " + proc);<a name="line.615"></a> +<span class="sourceLineNo">616</span> corrupted.add(proc);<a name="line.616"></a> +<span class="sourceLineNo">617</span> }<a name="line.617"></a> +<span class="sourceLineNo">618</span> }<a name="line.618"></a> +<span class="sourceLineNo">619</span> }<a name="line.619"></a> +<span class="sourceLineNo">620</span>}<a name="line.620"></a>
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/323b17d9/testdevapidocs/src-html/org/apache/hadoop/hbase/procedure2/ProcedureTestingUtility.NoopProcedure.html ---------------------------------------------------------------------- diff --git a/testdevapidocs/src-html/org/apache/hadoop/hbase/procedure2/ProcedureTestingUtility.NoopProcedure.html b/testdevapidocs/src-html/org/apache/hadoop/hbase/procedure2/ProcedureTestingUtility.NoopProcedure.html index edb675e..eb90a1f 100644 --- a/testdevapidocs/src-html/org/apache/hadoop/hbase/procedure2/ProcedureTestingUtility.NoopProcedure.html +++ b/testdevapidocs/src-html/org/apache/hadoop/hbase/procedure2/ProcedureTestingUtility.NoopProcedure.html @@ -408,184 +408,224 @@ <span class="sourceLineNo">400</span> }<a name="line.400"></a> <span class="sourceLineNo">401</span> }<a name="line.401"></a> <span class="sourceLineNo">402</span><a name="line.402"></a> -<span class="sourceLineNo">403</span> public static class TestProcedure extends NoopProcedure<Void> {<a name="line.403"></a> -<span class="sourceLineNo">404</span> private byte[] data = null;<a name="line.404"></a> -<span class="sourceLineNo">405</span><a name="line.405"></a> -<span class="sourceLineNo">406</span> public TestProcedure() {}<a name="line.406"></a> +<span class="sourceLineNo">403</span> public static class NoopStateMachineProcedure<TEnv, TState><a name="line.403"></a> +<span class="sourceLineNo">404</span> extends StateMachineProcedure<TEnv, TState> {<a name="line.404"></a> +<span class="sourceLineNo">405</span> private TState initialState;<a name="line.405"></a> +<span class="sourceLineNo">406</span> private TEnv env;<a name="line.406"></a> <span class="sourceLineNo">407</span><a name="line.407"></a> -<span class="sourceLineNo">408</span> public TestProcedure(long procId) {<a name="line.408"></a> -<span class="sourceLineNo">409</span> this(procId, 0);<a name="line.409"></a> -<span class="sourceLineNo">410</span> }<a name="line.410"></a> -<span class="sourceLineNo">411</span><a name="line.411"></a> -<span class="sourceLineNo">412</span> public TestProcedure(long procId, long parentId) {<a name="line.412"></a> -<span class="sourceLineNo">413</span> this(procId, parentId, null);<a name="line.413"></a> +<span class="sourceLineNo">408</span> public NoopStateMachineProcedure() {<a name="line.408"></a> +<span class="sourceLineNo">409</span> }<a name="line.409"></a> +<span class="sourceLineNo">410</span><a name="line.410"></a> +<span class="sourceLineNo">411</span> public NoopStateMachineProcedure(TEnv env, TState initialState) {<a name="line.411"></a> +<span class="sourceLineNo">412</span> this.env = env;<a name="line.412"></a> +<span class="sourceLineNo">413</span> this.initialState = initialState;<a name="line.413"></a> <span class="sourceLineNo">414</span> }<a name="line.414"></a> <span class="sourceLineNo">415</span><a name="line.415"></a> -<span class="sourceLineNo">416</span> public TestProcedure(long procId, long parentId, byte[] data) {<a name="line.416"></a> -<span class="sourceLineNo">417</span> this(procId, parentId, parentId, data);<a name="line.417"></a> -<span class="sourceLineNo">418</span> }<a name="line.418"></a> -<span class="sourceLineNo">419</span><a name="line.419"></a> -<span class="sourceLineNo">420</span> public TestProcedure(long procId, long parentId, long rootId, byte[] data) {<a name="line.420"></a> -<span class="sourceLineNo">421</span> setData(data);<a name="line.421"></a> -<span class="sourceLineNo">422</span> setProcId(procId);<a name="line.422"></a> -<span class="sourceLineNo">423</span> if (parentId > 0) {<a name="line.423"></a> -<span class="sourceLineNo">424</span> setParentProcId(parentId);<a name="line.424"></a> -<span class="sourceLineNo">425</span> }<a name="line.425"></a> -<span class="sourceLineNo">426</span> if (rootId > 0 || parentId > 0) {<a name="line.426"></a> -<span class="sourceLineNo">427</span> setRootProcId(rootId);<a name="line.427"></a> -<span class="sourceLineNo">428</span> }<a name="line.428"></a> -<span class="sourceLineNo">429</span> }<a name="line.429"></a> -<span class="sourceLineNo">430</span><a name="line.430"></a> -<span class="sourceLineNo">431</span> public void addStackId(final int index) {<a name="line.431"></a> -<span class="sourceLineNo">432</span> addStackIndex(index);<a name="line.432"></a> -<span class="sourceLineNo">433</span> }<a name="line.433"></a> -<span class="sourceLineNo">434</span><a name="line.434"></a> -<span class="sourceLineNo">435</span> public void setSuccessState() {<a name="line.435"></a> -<span class="sourceLineNo">436</span> setState(ProcedureState.SUCCESS);<a name="line.436"></a> -<span class="sourceLineNo">437</span> }<a name="line.437"></a> -<span class="sourceLineNo">438</span><a name="line.438"></a> -<span class="sourceLineNo">439</span> public void setData(final byte[] data) {<a name="line.439"></a> -<span class="sourceLineNo">440</span> this.data = data;<a name="line.440"></a> -<span class="sourceLineNo">441</span> }<a name="line.441"></a> +<span class="sourceLineNo">416</span> @Override<a name="line.416"></a> +<span class="sourceLineNo">417</span> protected Flow executeFromState(TEnv env, TState tState)<a name="line.417"></a> +<span class="sourceLineNo">418</span> throws ProcedureSuspendedException, ProcedureYieldException, InterruptedException {<a name="line.418"></a> +<span class="sourceLineNo">419</span> return null;<a name="line.419"></a> +<span class="sourceLineNo">420</span> }<a name="line.420"></a> +<span class="sourceLineNo">421</span><a name="line.421"></a> +<span class="sourceLineNo">422</span> @Override<a name="line.422"></a> +<span class="sourceLineNo">423</span> protected void rollbackState(TEnv env, TState tState) throws IOException, InterruptedException {<a name="line.423"></a> +<span class="sourceLineNo">424</span><a name="line.424"></a> +<span class="sourceLineNo">425</span> }<a name="line.425"></a> +<span class="sourceLineNo">426</span><a name="line.426"></a> +<span class="sourceLineNo">427</span> @Override<a name="line.427"></a> +<span class="sourceLineNo">428</span> protected TState getState(int stateId) {<a name="line.428"></a> +<span class="sourceLineNo">429</span> return null;<a name="line.429"></a> +<span class="sourceLineNo">430</span> }<a name="line.430"></a> +<span class="sourceLineNo">431</span><a name="line.431"></a> +<span class="sourceLineNo">432</span> @Override<a name="line.432"></a> +<span class="sourceLineNo">433</span> protected int getStateId(TState tState) {<a name="line.433"></a> +<span class="sourceLineNo">434</span> return 0;<a name="line.434"></a> +<span class="sourceLineNo">435</span> }<a name="line.435"></a> +<span class="sourceLineNo">436</span><a name="line.436"></a> +<span class="sourceLineNo">437</span> @Override<a name="line.437"></a> +<span class="sourceLineNo">438</span> protected TState getInitialState() {<a name="line.438"></a> +<span class="sourceLineNo">439</span> return initialState;<a name="line.439"></a> +<span class="sourceLineNo">440</span> }<a name="line.440"></a> +<span class="sourceLineNo">441</span> }<a name="line.441"></a> <span class="sourceLineNo">442</span><a name="line.442"></a> -<span class="sourceLineNo">443</span> @Override<a name="line.443"></a> -<span class="sourceLineNo">444</span> protected void serializeStateData(ProcedureStateSerializer serializer)<a name="line.444"></a> -<span class="sourceLineNo">445</span> throws IOException {<a name="line.445"></a> -<span class="sourceLineNo">446</span> ByteString dataString = ByteString.copyFrom((data == null) ? new byte[0] : data);<a name="line.446"></a> -<span class="sourceLineNo">447</span> BytesValue.Builder builder = BytesValue.newBuilder().setValue(dataString);<a name="line.447"></a> -<span class="sourceLineNo">448</span> serializer.serialize(builder.build());<a name="line.448"></a> -<span class="sourceLineNo">449</span> }<a name="line.449"></a> -<span class="sourceLineNo">450</span><a name="line.450"></a> -<span class="sourceLineNo">451</span> @Override<a name="line.451"></a> -<span class="sourceLineNo">452</span> protected void deserializeStateData(ProcedureStateSerializer serializer)<a name="line.452"></a> -<span class="sourceLineNo">453</span> throws IOException {<a name="line.453"></a> -<span class="sourceLineNo">454</span> BytesValue bytesValue = serializer.deserialize(BytesValue.class);<a name="line.454"></a> -<span class="sourceLineNo">455</span> ByteString dataString = bytesValue.getValue();<a name="line.455"></a> -<span class="sourceLineNo">456</span><a name="line.456"></a> -<span class="sourceLineNo">457</span> if (dataString.isEmpty()) {<a name="line.457"></a> -<span class="sourceLineNo">458</span> data = null;<a name="line.458"></a> -<span class="sourceLineNo">459</span> } else {<a name="line.459"></a> -<span class="sourceLineNo">460</span> data = dataString.toByteArray();<a name="line.460"></a> -<span class="sourceLineNo">461</span> }<a name="line.461"></a> -<span class="sourceLineNo">462</span> }<a name="line.462"></a> -<span class="sourceLineNo">463</span><a name="line.463"></a> -<span class="sourceLineNo">464</span> // Mark acquire/release lock functions public for test uses.<a name="line.464"></a> -<span class="sourceLineNo">465</span> @Override<a name="line.465"></a> -<span class="sourceLineNo">466</span> public LockState acquireLock(Void env) {<a name="line.466"></a> -<span class="sourceLineNo">467</span> return LockState.LOCK_ACQUIRED;<a name="line.467"></a> -<span class="sourceLineNo">468</span> }<a name="line.468"></a> -<span class="sourceLineNo">469</span><a name="line.469"></a> -<span class="sourceLineNo">470</span> @Override<a name="line.470"></a> -<span class="sourceLineNo">471</span> public void releaseLock(Void env) {<a name="line.471"></a> -<span class="sourceLineNo">472</span> // no-op<a name="line.472"></a> +<span class="sourceLineNo">443</span> public static class TestProcedure extends NoopProcedure<Void> {<a name="line.443"></a> +<span class="sourceLineNo">444</span> private byte[] data = null;<a name="line.444"></a> +<span class="sourceLineNo">445</span><a name="line.445"></a> +<span class="sourceLineNo">446</span> public TestProcedure() {}<a name="line.446"></a> +<span class="sourceLineNo">447</span><a name="line.447"></a> +<span class="sourceLineNo">448</span> public TestProcedure(long procId) {<a name="line.448"></a> +<span class="sourceLineNo">449</span> this(procId, 0);<a name="line.449"></a> +<span class="sourceLineNo">450</span> }<a name="line.450"></a> +<span class="sourceLineNo">451</span><a name="line.451"></a> +<span class="sourceLineNo">452</span> public TestProcedure(long procId, long parentId) {<a name="line.452"></a> +<span class="sourceLineNo">453</span> this(procId, parentId, null);<a name="line.453"></a> +<span class="sourceLineNo">454</span> }<a name="line.454"></a> +<span class="sourceLineNo">455</span><a name="line.455"></a> +<span class="sourceLineNo">456</span> public TestProcedure(long procId, long parentId, byte[] data) {<a name="line.456"></a> +<span class="sourceLineNo">457</span> this(procId, parentId, parentId, data);<a name="line.457"></a> +<span class="sourceLineNo">458</span> }<a name="line.458"></a> +<span class="sourceLineNo">459</span><a name="line.459"></a> +<span class="sourceLineNo">460</span> public TestProcedure(long procId, long parentId, long rootId, byte[] data) {<a name="line.460"></a> +<span class="sourceLineNo">461</span> setData(data);<a name="line.461"></a> +<span class="sourceLineNo">462</span> setProcId(procId);<a name="line.462"></a> +<span class="sourceLineNo">463</span> if (parentId > 0) {<a name="line.463"></a> +<span class="sourceLineNo">464</span> setParentProcId(parentId);<a name="line.464"></a> +<span class="sourceLineNo">465</span> }<a name="line.465"></a> +<span class="sourceLineNo">466</span> if (rootId > 0 || parentId > 0) {<a name="line.466"></a> +<span class="sourceLineNo">467</span> setRootProcId(rootId);<a name="line.467"></a> +<span class="sourceLineNo">468</span> }<a name="line.468"></a> +<span class="sourceLineNo">469</span> }<a name="line.469"></a> +<span class="sourceLineNo">470</span><a name="line.470"></a> +<span class="sourceLineNo">471</span> public void addStackId(final int index) {<a name="line.471"></a> +<span class="sourceLineNo">472</span> addStackIndex(index);<a name="line.472"></a> <span class="sourceLineNo">473</span> }<a name="line.473"></a> -<span class="sourceLineNo">474</span> }<a name="line.474"></a> -<span class="sourceLineNo">475</span><a name="line.475"></a> -<span class="sourceLineNo">476</span> public static class LoadCounter implements ProcedureStore.ProcedureLoader {<a name="line.476"></a> -<span class="sourceLineNo">477</span> private final ArrayList<Procedure> corrupted = new ArrayList<>();<a name="line.477"></a> -<span class="sourceLineNo">478</span> private final ArrayList<Procedure> completed = new ArrayList<>();<a name="line.478"></a> -<span class="sourceLineNo">479</span> private final ArrayList<Procedure> runnable = new ArrayList<>();<a name="line.479"></a> -<span class="sourceLineNo">480</span><a name="line.480"></a> -<span class="sourceLineNo">481</span> private Set<Long> procIds;<a name="line.481"></a> -<span class="sourceLineNo">482</span> private long maxProcId = 0;<a name="line.482"></a> -<span class="sourceLineNo">483</span><a name="line.483"></a> -<span class="sourceLineNo">484</span> public LoadCounter() {<a name="line.484"></a> -<span class="sourceLineNo">485</span> this(null);<a name="line.485"></a> -<span class="sourceLineNo">486</span> }<a name="line.486"></a> -<span class="sourceLineNo">487</span><a name="line.487"></a> -<span class="sourceLineNo">488</span> public LoadCounter(final Set<Long> procIds) {<a name="line.488"></a> -<span class="sourceLineNo">489</span> this.procIds = procIds;<a name="line.489"></a> -<span class="sourceLineNo">490</span> }<a name="line.490"></a> -<span class="sourceLineNo">491</span><a name="line.491"></a> -<span class="sourceLineNo">492</span> public void reset() {<a name="line.492"></a> -<span class="sourceLineNo">493</span> reset(null);<a name="line.493"></a> -<span class="sourceLineNo">494</span> }<a name="line.494"></a> -<span class="sourceLineNo">495</span><a name="line.495"></a> -<span class="sourceLineNo">496</span> public void reset(final Set<Long> procIds) {<a name="line.496"></a> -<span class="sourceLineNo">497</span> corrupted.clear();<a name="line.497"></a> -<span class="sourceLineNo">498</span> completed.clear();<a name="line.498"></a> -<span class="sourceLineNo">499</span> runnable.clear();<a name="line.499"></a> -<span class="sourceLineNo">500</span> this.procIds = procIds;<a name="line.500"></a> -<span class="sourceLineNo">501</span> this.maxProcId = 0;<a name="line.501"></a> +<span class="sourceLineNo">474</span><a name="line.474"></a> +<span class="sourceLineNo">475</span> public void setSuccessState() {<a name="line.475"></a> +<span class="sourceLineNo">476</span> setState(ProcedureState.SUCCESS);<a name="line.476"></a> +<span class="sourceLineNo">477</span> }<a name="line.477"></a> +<span class="sourceLineNo">478</span><a name="line.478"></a> +<span class="sourceLineNo">479</span> public void setData(final byte[] data) {<a name="line.479"></a> +<span class="sourceLineNo">480</span> this.data = data;<a name="line.480"></a> +<span class="sourceLineNo">481</span> }<a name="line.481"></a> +<span class="sourceLineNo">482</span><a name="line.482"></a> +<span class="sourceLineNo">483</span> @Override<a name="line.483"></a> +<span class="sourceLineNo">484</span> protected void serializeStateData(ProcedureStateSerializer serializer)<a name="line.484"></a> +<span class="sourceLineNo">485</span> throws IOException {<a name="line.485"></a> +<span class="sourceLineNo">486</span> ByteString dataString = ByteString.copyFrom((data == null) ? new byte[0] : data);<a name="line.486"></a> +<span class="sourceLineNo">487</span> BytesValue.Builder builder = BytesValue.newBuilder().setValue(dataString);<a name="line.487"></a> +<span class="sourceLineNo">488</span> serializer.serialize(builder.build());<a name="line.488"></a> +<span class="sourceLineNo">489</span> }<a name="line.489"></a> +<span class="sourceLineNo">490</span><a name="line.490"></a> +<span class="sourceLineNo">491</span> @Override<a name="line.491"></a> +<span class="sourceLineNo">492</span> protected void deserializeStateData(ProcedureStateSerializer serializer)<a name="line.492"></a> +<span class="sourceLineNo">493</span> throws IOException {<a name="line.493"></a> +<span class="sourceLineNo">494</span> BytesValue bytesValue = serializer.deserialize(BytesValue.class);<a name="line.494"></a> +<span class="sourceLineNo">495</span> ByteString dataString = bytesValue.getValue();<a name="line.495"></a> +<span class="sourceLineNo">496</span><a name="line.496"></a> +<span class="sourceLineNo">497</span> if (dataString.isEmpty()) {<a name="line.497"></a> +<span class="sourceLineNo">498</span> data = null;<a name="line.498"></a> +<span class="sourceLineNo">499</span> } else {<a name="line.499"></a> +<span class="sourceLineNo">500</span> data = dataString.toByteArray();<a name="line.500"></a> +<span class="sourceLineNo">501</span> }<a name="line.501"></a> <span class="sourceLineNo">502</span> }<a name="line.502"></a> <span class="sourceLineNo">503</span><a name="line.503"></a> -<span class="sourceLineNo">504</span> public long getMaxProcId() {<a name="line.504"></a> -<span class="sourceLineNo">505</span> return maxProcId;<a name="line.505"></a> -<span class="sourceLineNo">506</span> }<a name="line.506"></a> -<span class="sourceLineNo">507</span><a name="line.507"></a> -<span class="sourceLineNo">508</span> public ArrayList<Procedure> getRunnables() {<a name="line.508"></a> -<span class="sourceLineNo">509</span> return runnable;<a name="line.509"></a> -<span class="sourceLineNo">510</span> }<a name="line.510"></a> -<span class="sourceLineNo">511</span><a name="line.511"></a> -<span class="sourceLineNo">512</span> public int getRunnableCount() {<a name="line.512"></a> -<span class="sourceLineNo">513</span> return runnable.size();<a name="line.513"></a> -<span class="sourceLineNo">514</span> }<a name="line.514"></a> +<span class="sourceLineNo">504</span> // Mark acquire/release lock functions public for test uses.<a name="line.504"></a> +<span class="sourceLineNo">505</span> @Override<a name="line.505"></a> +<span class="sourceLineNo">506</span> public LockState acquireLock(Void env) {<a name="line.506"></a> +<span class="sourceLineNo">507</span> return LockState.LOCK_ACQUIRED;<a name="line.507"></a> +<span class="sourceLineNo">508</span> }<a name="line.508"></a> +<span class="sourceLineNo">509</span><a name="line.509"></a> +<span class="sourceLineNo">510</span> @Override<a name="line.510"></a> +<span class="sourceLineNo">511</span> public void releaseLock(Void env) {<a name="line.511"></a> +<span class="sourceLineNo">512</span> // no-op<a name="line.512"></a> +<span class="sourceLineNo">513</span> }<a name="line.513"></a> +<span class="sourceLineNo">514</span> }<a name="line.514"></a> <span class="sourceLineNo">515</span><a name="line.515"></a> -<span class="sourceLineNo">516</span> public ArrayList<Procedure> getCompleted() {<a name="line.516"></a> -<span class="sourceLineNo">517</span> return completed;<a name="line.517"></a> -<span class="sourceLineNo">518</span> }<a name="line.518"></a> -<span class="sourceLineNo">519</span><a name="line.519"></a> -<span class="sourceLineNo">520</span> public int getCompletedCount() {<a name="line.520"></a> -<span class="sourceLineNo">521</span> return completed.size();<a name="line.521"></a> -<span class="sourceLineNo">522</span> }<a name="line.522"></a> +<span class="sourceLineNo">516</span> public static class LoadCounter implements ProcedureStore.ProcedureLoader {<a name="line.516"></a> +<span class="sourceLineNo">517</span> private final ArrayList<Procedure> corrupted = new ArrayList<>();<a name="line.517"></a> +<span class="sourceLineNo">518</span> private final ArrayList<Procedure> completed = new ArrayList<>();<a name="line.518"></a> +<span class="sourceLineNo">519</span> private final ArrayList<Procedure> runnable = new ArrayList<>();<a name="line.519"></a> +<span class="sourceLineNo">520</span><a name="line.520"></a> +<span class="sourceLineNo">521</span> private Set<Long> procIds;<a name="line.521"></a> +<span class="sourceLineNo">522</span> private long maxProcId = 0;<a name="line.522"></a> <span class="sourceLineNo">523</span><a name="line.523"></a> -<span class="sourceLineNo">524</span> public int getLoadedCount() {<a name="line.524"></a> -<span class="sourceLineNo">525</span> return runnable.size() + completed.size();<a name="line.525"></a> +<span class="sourceLineNo">524</span> public LoadCounter() {<a name="line.524"></a> +<span class="sourceLineNo">525</span> this(null);<a name="line.525"></a> <span class="sourceLineNo">526</span> }<a name="line.526"></a> <span class="sourceLineNo">527</span><a name="line.527"></a> -<span class="sourceLineNo">528</span> public ArrayList<Procedure> getCorrupted() {<a name="line.528"></a> -<span class="sourceLineNo">529</span> return corrupted;<a name="line.529"></a> +<span class="sourceLineNo">528</span> public LoadCounter(final Set<Long> procIds) {<a name="line.528"></a> +<span class="sourceLineNo">529</span> this.procIds = procIds;<a name="line.529"></a> <span class="sourceLineNo">530</span> }<a name="line.530"></a> <span class="sourceLineNo">531</span><a name="line.531"></a> -<span class="sourceLineNo">532</span> public int getCorruptedCount() {<a name="line.532"></a> -<span class="sourceLineNo">533</span> return corrupted.size();<a name="line.533"></a> +<span class="sourceLineNo">532</span> public void reset() {<a name="line.532"></a> +<span class="sourceLineNo">533</span> reset(null);<a name="line.533"></a> <span class="sourceLineNo">534</span> }<a name="line.534"></a> <span class="sourceLineNo">535</span><a name="line.535"></a> -<span class="sourceLineNo">536</span> public boolean isRunnable(final long procId) {<a name="line.536"></a> -<span class="sourceLineNo">537</span> for (Procedure proc: runnable) {<a name="line.537"></a> -<span class="sourceLineNo">538</span> if (proc.getProcId() == procId) {<a name="line.538"></a> -<span class="sourceLineNo">539</span> return true;<a name="line.539"></a> -<span class="sourceLineNo">540</span> }<a name="line.540"></a> -<span class="sourceLineNo">541</span> }<a name="line.541"></a> -<span class="sourceLineNo">542</span> return false;<a name="line.542"></a> -<span class="sourceLineNo">543</span> }<a name="line.543"></a> -<span class="sourceLineNo">544</span><a name="line.544"></a> -<span class="sourceLineNo">545</span> @Override<a name="line.545"></a> -<span class="sourceLineNo">546</span> public void setMaxProcId(long maxProcId) {<a name="line.546"></a> -<span class="sourceLineNo">547</span> this.maxProcId = maxProcId;<a name="line.547"></a> -<span class="sourceLineNo">548</span> }<a name="line.548"></a> -<span class="sourceLineNo">549</span><a name="line.549"></a> -<span class="sourceLineNo">550</span> @Override<a name="line.550"></a> -<span class="sourceLineNo">551</span> public void load(ProcedureIterator procIter) throws IOException {<a name="line.551"></a> -<span class="sourceLineNo">552</span> while (procIter.hasNext()) {<a name="line.552"></a> -<span class="sourceLineNo">553</span> long procId;<a name="line.553"></a> -<span class="sourceLineNo">554</span> if (procIter.isNextFinished()) {<a name="line.554"></a> -<span class="sourceLineNo">555</span> Procedure<?> proc = procIter.next();<a name="line.555"></a> -<span class="sourceLineNo">556</span> procId = proc.getProcId();<a name="line.556"></a> -<span class="sourceLineNo">557</span> LOG.debug("loading completed procId=" + procId + ": " + proc);<a name="line.557"></a> -<span class="sourceLineNo">558</span> completed.add(proc);<a name="line.558"></a> -<span class="sourceLineNo">559</span> } else {<a name="line.559"></a> -<span class="sourceLineNo">560</span> Procedure proc = procIter.next();<a name="line.560"></a> -<span class="sourceLineNo">561</span> procId = proc.getProcId();<a name="line.561"></a> -<span class="sourceLineNo">562</span> LOG.debug("loading runnable procId=" + procId + ": " + proc);<a name="line.562"></a> -<span class="sourceLineNo">563</span> runnable.add(proc);<a name="line.563"></a> -<span class="sourceLineNo">564</span> }<a name="line.564"></a> -<span class="sourceLineNo">565</span> if (procIds != null) {<a name="line.565"></a> -<span class="sourceLineNo">566</span> assertTrue("procId=" + procId + " unexpected", procIds.contains(procId));<a name="line.566"></a> -<span class="sourceLineNo">567</span> }<a name="line.567"></a> -<span class="sourceLineNo">568</span> }<a name="line.568"></a> -<span class="sourceLineNo">569</span> }<a name="line.569"></a> -<span class="sourceLineNo">570</span><a name="line.570"></a> -<span class="sourceLineNo">571</span> @Override<a name="line.571"></a> -<span class="sourceLineNo">572</span> public void handleCorrupted(ProcedureIterator procIter) throws IOException {<a name="line.572"></a> -<span class="sourceLineNo">573</span> while (procIter.hasNext()) {<a name="line.573"></a> -<span class="sourceLineNo">574</span> Procedure proc = procIter.next();<a name="line.574"></a> -<span class="sourceLineNo">575</span> LOG.debug("corrupted procId=" + proc.getProcId() + ": " + proc);<a name="line.575"></a> -<span class="sourceLineNo">576</span> corrupted.add(proc);<a name="line.576"></a> -<span class="sourceLineNo">577</span> }<a name="line.577"></a> -<span class="sourceLineNo">578</span> }<a name="line.578"></a> -<span class="sourceLineNo">579</span> }<a name="line.579"></a> -<span class="sourceLineNo">580</span>}<a name="line.580"></a> +<span class="sourceLineNo">536</span> public void reset(final Set<Long> procIds) {<a name="line.536"></a> +<span class="sourceLineNo">537</span> corrupted.clear();<a name="line.537"></a> +<span class="sourceLineNo">538</span> completed.clear();<a name="line.538"></a> +<span class="sourceLineNo">539</span> runnable.clear();<a name="line.539"></a> +<span class="sourceLineNo">540</span> this.procIds = procIds;<a name="line.540"></a> +<span class="sourceLineNo">541</span> this.maxProcId = 0;<a name="line.541"></a> +<span class="sourceLineNo">542</span> }<a name="line.542"></a> +<span class="sourceLineNo">543</span><a name="line.543"></a> +<span class="sourceLineNo">544</span> public long getMaxProcId() {<a name="line.544"></a> +<span class="sourceLineNo">545</span> return maxProcId;<a name="line.545"></a> +<span class="sourceLineNo">546</span> }<a name="line.546"></a> +<span class="sourceLineNo">547</span><a name="line.547"></a> +<span class="sourceLineNo">548</span> public ArrayList<Procedure> getRunnables() {<a name="line.548"></a> +<span class="sourceLineNo">549</span> return runnable;<a name="line.549"></a> +<span class="sourceLineNo">550</span> }<a name="line.550"></a> +<span class="sourceLineNo">551</span><a name="line.551"></a> +<span class="sourceLineNo">552</span> public int getRunnableCount() {<a name="line.552"></a> +<span class="sourceLineNo">553</span> return runnable.size();<a name="line.553"></a> +<span class="sourceLineNo">554</span> }<a name="line.554"></a> +<span class="sourceLineNo">555</span><a name="line.555"></a> +<span class="sourceLineNo">556</span> public ArrayList<Procedure> getCompleted() {<a name="line.556"></a> +<span class="sourceLineNo">557</span> return completed;<a name="line.557"></a> +<span class="sourceLineNo">558</span> }<a name="line.558"></a> +<span class="sourceLineNo">559</span><a name="line.559"></a> +<span class="sourceLineNo">560</span> public int getCompletedCount() {<a name="line.560"></a> +<span class="sourceLineNo">561</span> return completed.size();<a name="line.561"></a> +<span class="sourceLineNo">562</span> }<a name="line.562"></a> +<span class="sourceLineNo">563</span><a name="line.563"></a> +<span class="sourceLineNo">564</span> public int getLoadedCount() {<a name="line.564"></a> +<span class="sourceLineNo">565</span> return runnable.size() + completed.size();<a name="line.565"></a> +<span class="sourceLineNo">566</span> }<a name="line.566"></a> +<span class="sourceLineNo">567</span><a name="line.567"></a> +<span class="sourceLineNo">568</span> public ArrayList<Procedure> getCorrupted() {<a name="line.568"></a> +<span class="sourceLineNo">569</span> return corrupted;<a name="line.569"></a> +<span class="sourceLineNo">570</span> }<a name="line.570"></a> +<span class="sourceLineNo">571</span><a name="line.571"></a> +<span class="sourceLineNo">572</span> public int getCorruptedCount() {<a name="line.572"></a> +<span class="sourceLineNo">573</span> return corrupted.size();<a name="line.573"></a> +<span class="sourceLineNo">574</span> }<a name="line.574"></a> +<span class="sourceLineNo">575</span><a name="line.575"></a> +<span class="sourceLineNo">576</span> public boolean isRunnable(final long procId) {<a name="line.576"></a> +<span class="sourceLineNo">577</span> for (Procedure proc: runnable) {<a name="line.577"></a> +<span class="sourceLineNo">578</span> if (proc.getProcId() == procId) {<a name="line.578"></a> +<span class="sourceLineNo">579</span> return true;<a name="line.579"></a> +<span class="sourceLineNo">580</span> }<a name="line.580"></a> +<span class="sourceLineNo">581</span> }<a name="line.581"></a> +<span class="sourceLineNo">582</span> return false;<a name="line.582"></a> +<span class="sourceLineNo">583</span> }<a name="line.583"></a> +<span class="sourceLineNo">584</span><a name="line.584"></a> +<span class="sourceLineNo">585</span> @Override<a name="line.585"></a> +<span class="sourceLineNo">586</span> public void setMaxProcId(long maxProcId) {<a name="line.586"></a> +<span class="sourceLineNo">587</span> this.maxProcId = maxProcId;<a name="line.587"></a> +<span class="sourceLineNo">588</span> }<a name="line.588"></a> +<span class="sourceLineNo">589</span><a name="line.589"></a> +<span class="sourceLineNo">590</span> @Override<a name="line.590"></a> +<span class="sourceLineNo">591</span> public void load(ProcedureIterator procIter) throws IOException {<a name="line.591"></a> +<span class="sourceLineNo">592</span> while (procIter.hasNext()) {<a name="line.592"></a> +<span class="sourceLineNo">593</span> long procId;<a name="line.593"></a> +<span class="sourceLineNo">594</span> if (procIter.isNextFinished()) {<a name="line.594"></a> +<span class="sourceLineNo">595</span> Procedure<?> proc = procIter.next();<a name="line.595"></a> +<span class="sourceLineNo">596</span> procId = proc.getProcId();<a name="line.596"></a> +<span class="sourceLineNo">597</span> LOG.debug("loading completed procId=" + procId + ": " + proc);<a name="line.597"></a> +<span class="sourceLineNo">598</span> completed.add(proc);<a name="line.598"></a> +<span class="sourceLineNo">599</span> } else {<a name="line.599"></a> +<span class="sourceLineNo">600</span> Procedure proc = procIter.next();<a name="line.600"></a> +<span class="sourceLineNo">601</span> procId = proc.getProcId();<a name="line.601"></a> +<span class="sourceLineNo">602</span> LOG.debug("loading runnable procId=" + procId + ": " + proc);<a name="line.602"></a> +<span class="sourceLineNo">603</span> runnable.add(proc);<a name="line.603"></a> +<span class="sourceLineNo">604</span> }<a name="line.604"></a> +<span class="sourceLineNo">605</span> if (procIds != null) {<a name="line.605"></a> +<span class="sourceLineNo">606</span> assertTrue("procId=" + procId + " unexpected", procIds.contains(procId));<a name="line.606"></a> +<span class="sourceLineNo">607</span> }<a name="line.607"></a> +<span class="sourceLineNo">608</span> }<a name="line.608"></a> +<span class="sourceLineNo">609</span> }<a name="line.609"></a> +<span class="sourceLineNo">610</span><a name="line.610"></a> +<span class="sourceLineNo">611</span> @Override<a name="line.611"></a> +<span class="sourceLineNo">612</span> public void handleCorrupted(ProcedureIterator procIter) throws IOException {<a name="line.612"></a> +<span class="sourceLineNo">613</span> while (procIter.hasNext()) {<a name="line.613"></a> +<span class="sourceLineNo">614</span> Procedure proc = procIter.next();<a name="line.614"></a> +<span class="sourceLineNo">615</span> LOG.debug("corrupted procId=" + proc.getProcId() + ": " + proc);<a name="line.615"></a> +<span class="sourceLineNo">616</span> corrupted.add(proc);<a name="line.616"></a> +<span class="sourceLineNo">617</span> }<a name="line.617"></a> +<span class="sourceLineNo">618</span> }<a name="line.618"></a> +<span class="sourceLineNo">619</span> }<a name="line.619"></a> +<span class="sourceLineNo">620</span>}<a name="line.620"></a>