Search in sources :

Example 1 with StoreCodecException

use of io.dingodb.store.row.errors.StoreCodecException in project dingo by dingodb.

the class KVStoreStateMachine method onApply.

@Override
public void onApply(final Iterator it) {
    int index = 0;
    int applied = 0;
    try {
        KVStateOutputList kvStates = KVStateOutputList.newInstance();
        while (it.hasNext()) {
            KVOperation kvOp;
            final KVClosureAdapter done = (KVClosureAdapter) it.done();
            if (done != null) {
                kvOp = done.getOperation();
            } else {
                final ByteBuffer buf = it.getData();
                try {
                    if (buf.hasArray()) {
                        kvOp = this.serializer.readObject(buf.array(), KVOperation.class);
                    } else {
                        kvOp = this.serializer.readObject(buf, KVOperation.class);
                    }
                } catch (final Throwable t) {
                    ++index;
                    throw new StoreCodecException("Decode operation error", t);
                }
            }
            final KVState first = kvStates.getFirstElement();
            if (first != null && !first.isSameOp(kvOp)) {
                applied += batchApplyAndRecycle(first.getOpByte(), kvStates);
                kvStates = KVStateOutputList.newInstance();
            }
            kvStates.add(KVState.of(kvOp, done));
            ++index;
            it.next();
        }
        if (!kvStates.isEmpty()) {
            final KVState first = kvStates.getFirstElement();
            assert first != null;
            applied += batchApplyAndRecycle(first.getOpByte(), kvStates);
        }
    } catch (final Throwable t) {
        LOG.error("StateMachine meet critical error: {}.", StackTraceUtil.stackTrace(t));
        it.setErrorAndRollback(index - applied, new Status(RaftError.ESTATEMACHINE, "StateMachine meet critical error: %s.", t.getMessage()));
    } finally {
        // metrics: qps
        this.applyMeter.mark(applied);
    }
}
Also used : Status(io.dingodb.raft.Status) StoreCodecException(io.dingodb.store.row.errors.StoreCodecException) ByteBuffer(java.nio.ByteBuffer)

Example 2 with StoreCodecException

use of io.dingodb.store.row.errors.StoreCodecException in project dingo by dingodb.

the class CoordinatorStateMachine method onApply.

@Override
public void onApply(final Iterator it) {
    int index = 0;
    int applied = 0;
    try {
        KVStateOutputList kvStates = KVStateOutputList.newInstance();
        while (it.hasNext()) {
            KVOperation kvOp;
            final KVClosureAdapter done = (KVClosureAdapter) it.done();
            if (done != null) {
                kvOp = done.getOperation();
            } else {
                final ByteBuffer buf = it.getData();
                try {
                    if (buf.hasArray()) {
                        kvOp = this.serializer.readObject(buf.array(), KVOperation.class);
                    } else {
                        kvOp = this.serializer.readObject(buf, KVOperation.class);
                    }
                } catch (final Throwable t) {
                    ++index;
                    throw new StoreCodecException("Decode operation error", t);
                }
            }
            final KVState first = kvStates.getFirstElement();
            if (first != null && !first.isSameOp(kvOp)) {
                applied += batchApplyAndRecycle(first.getOpByte(), kvStates);
                kvStates = KVStateOutputList.newInstance();
            }
            kvStates.add(KVState.of(kvOp, done));
            ++index;
            it.next();
        }
        if (!kvStates.isEmpty()) {
            final KVState first = kvStates.getFirstElement();
            assert first != null;
            applied += batchApplyAndRecycle(first.getOpByte(), kvStates);
        }
    } catch (final Throwable t) {
        log.error("StateMachine meet critical error: {}.", StackTraceUtil.stackTrace(t));
        it.setErrorAndRollback(index - applied, new Status(RaftError.ESTATEMACHINE, "StateMachine meet critical error: %s.", t.getMessage()));
    } finally {
        // metrics: qps
        this.applyMeter.mark(applied);
    }
}
Also used : Status(io.dingodb.raft.Status) KVClosureAdapter(io.dingodb.store.row.storage.KVClosureAdapter) StoreCodecException(io.dingodb.store.row.errors.StoreCodecException) KVStateOutputList(io.dingodb.store.row.storage.KVStateOutputList) KVOperation(io.dingodb.store.row.storage.KVOperation) ByteBuffer(java.nio.ByteBuffer) KVState(io.dingodb.store.row.storage.KVState)

Aggregations

Status (io.dingodb.raft.Status)2 StoreCodecException (io.dingodb.store.row.errors.StoreCodecException)2 ByteBuffer (java.nio.ByteBuffer)2 KVClosureAdapter (io.dingodb.store.row.storage.KVClosureAdapter)1 KVOperation (io.dingodb.store.row.storage.KVOperation)1 KVState (io.dingodb.store.row.storage.KVState)1 KVStateOutputList (io.dingodb.store.row.storage.KVStateOutputList)1