Java Code Examples for org.apache.zookeeper.Op#setData()

The following examples show how to use org.apache.zookeeper.Op#setData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BKLogWriteHandler.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
void storeMaxTxId(final ZKTransaction txn,
                  final MaxTxId maxTxId,
                  final long txId) {
    byte[] data = maxTxId.couldStore(txId);
    if (null != data) {
        Op zkOp = Op.setData(maxTxId.getZkPath(), data, -1);
        txn.addOp(new ZKVersionedSetOp(zkOp, new Transaction.OpListener<Version>() {
            @Override
            public void onCommit(Version version) {
                maxTxId.setMaxTxId(txId);
            }

            @Override
            public void onAbort(Throwable t) {

            }
        }));
    }
}
 
Example 2
Source File: ZKUtil.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Convert from ZKUtilOp to ZKOp
 */
private static Op toZooKeeperOp(ZKWatcher zkw, ZKUtilOp op) throws UnsupportedOperationException {
  if(op == null) {
    return null;
  }

  if (op instanceof CreateAndFailSilent) {
    CreateAndFailSilent cafs = (CreateAndFailSilent)op;
    return Op.create(cafs.getPath(), cafs.getData(), createACL(zkw, cafs.getPath()),
      CreateMode.PERSISTENT);
  } else if (op instanceof DeleteNodeFailSilent) {
    DeleteNodeFailSilent dnfs = (DeleteNodeFailSilent)op;
    return Op.delete(dnfs.getPath(), -1);
  } else if (op instanceof SetData) {
    SetData sd = (SetData) op;
    return Op.setData(sd.getPath(), sd.getData(), sd.getVersion());
  } else {
    throw new UnsupportedOperationException("Unexpected ZKUtilOp type: "
      + op.getClass().getName());
  }
}
 
Example 3
Source File: ZKLogSegmentMetadataStore.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@Override
public void storeMaxLogSegmentSequenceNumber(Transaction<Object> txn,
                                             LogMetadata logMetadata,
                                             Versioned<Long> lssn,
                                             Transaction.OpListener<Version> listener) {
    Version version = lssn.getVersion();
    assert(version instanceof LongVersion);
    LongVersion zkVersion = (LongVersion) version;
    byte[] data = DLUtils.serializeLogSegmentSequenceNumber(lssn.getValue());
    Op setDataOp = Op.setData(logMetadata.getLogSegmentsPath(), data, (int) zkVersion.getLongVersion());
    ZKOp zkOp = new ZKVersionedSetOp(setDataOp, listener);
    txn.addOp(zkOp);
}
 
Example 4
Source File: ZKLogSegmentMetadataStore.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@Override
public void storeMaxTxnId(Transaction<Object> txn,
                          LogMetadataForWriter logMetadata,
                          Versioned<Long> transactionId,
                          Transaction.OpListener<Version> listener) {
    Version version = transactionId.getVersion();
    assert(version instanceof LongVersion);
    LongVersion zkVersion = (LongVersion) version;
    byte[] data = DLUtils.serializeTransactionId(transactionId.getValue());
    Op setDataOp = Op.setData(logMetadata.getMaxTxIdPath(), data, (int) zkVersion.getLongVersion());
    ZKOp zkOp = new ZKVersionedSetOp(setDataOp, listener);
    txn.addOp(zkOp);
}
 
Example 5
Source File: BKLogWriteHandler.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
void storeMaxSequenceNumber(final Transaction txn,
                            final MaxLogSegmentSequenceNo maxSeqNo,
                            final long seqNo,
                            final boolean isInprogress) {
    byte[] data = DLUtils.serializeLogSegmentSequenceNumber(seqNo);
    Op zkOp = Op.setData(logMetadata.getLogSegmentsPath(), data, maxSeqNo.getZkVersion());
    txn.addOp(new ZKVersionedSetOp(zkOp, new Transaction.OpListener<Version>() {
        @Override
        public void onCommit(Version version) {
            if (validateLogSegmentSequenceNumber) {
                synchronized (inprogressLSSNs) {
                    if (isInprogress) {
                        inprogressLSSNs.add(seqNo);
                    } else {
                        inprogressLSSNs.removeFirst();
                    }
                }
            }
            maxSeqNo.update((ZkVersion) version, seqNo);
        }

        @Override
        public void onAbort(Throwable t) {
            // no-op
        }
    }));
}
 
Example 6
Source File: ZKLogSegmentMetadataStore.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@Override
public void storeMaxLogSegmentSequenceNumber(Transaction<Object> txn,
                                             String path,
                                             Versioned<Long> lssn,
                                             Transaction.OpListener<Version> listener) {
    Version version = lssn.getVersion();
    assert(version instanceof ZkVersion);

    ZkVersion zkVersion = (ZkVersion) version;
    byte[] data = DLUtils.serializeLogSegmentSequenceNumber(lssn.getValue());
    Op setDataOp = Op.setData(path, data, zkVersion.getZnodeVersion());
    ZKOp zkOp = new ZKVersionedSetOp(setDataOp, listener);
    txn.addOp(zkOp);
}
 
Example 7
Source File: ZKLogSegmentMetadataStore.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@Override
public void storeMaxTxnId(Transaction<Object> txn,
                          String path,
                          Versioned<Long> transactionId,
                          Transaction.OpListener<Version> listener) {
    Version version = transactionId.getVersion();
    assert(version instanceof ZkVersion);

    ZkVersion zkVersion = (ZkVersion) version;
    byte[] data = DLUtils.serializeTransactionId(transactionId.getValue());
    Op setDataOp = Op.setData(path, data, zkVersion.getZnodeVersion());
    ZKOp zkOp = new ZKVersionedSetOp(setDataOp, listener);
    txn.addOp(zkOp);
}
 
Example 8
Source File: ZKLogSegmentMetadataStore.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
@Override
public void updateLogSegment(Transaction<Object> txn, LogSegmentMetadata segment) {
    byte[] finalisedData = segment.getFinalisedData().getBytes(UTF_8);
    Op updateOp = Op.setData(segment.getZkPath(), finalisedData, -1);
    txn.addOp(DefaultZKOp.of(updateOp, null));
}
 
Example 9
Source File: ZKLogSegmentMetadataStore.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
@Override
public void updateLogSegment(Transaction<Object> txn, LogSegmentMetadata segment) {
    byte[] finalisedData = segment.getFinalisedData().getBytes(UTF_8);
    Op updateOp = Op.setData(segment.getZkPath(), finalisedData, -1);
    txn.addOp(DefaultZKOp.of(updateOp));
}