ZKLogSegmentMetadataStore implements LogSegmentMetadataStore, Watcher, Children2Callback { @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); } ZKLogSegmentMetadataStore(DistributedLogConfiguration conf,
                                     ZooKeeperClient zkc,
                                     OrderedScheduler scheduler); @Override void storeMaxLogSegmentSequenceNumber(Transaction<Object> txn,
                                                 String path,
                                                 Versioned<Long> lssn,
                                                 Transaction.OpListener<Version> listener); @Override void storeMaxTxnId(Transaction<Object> txn,
                              String path,
                              Versioned<Long> transactionId,
                              Transaction.OpListener<Version> listener); @Override Transaction<Object> transaction(); @Override void createLogSegment(Transaction<Object> txn, LogSegmentMetadata segment); @Override void deleteLogSegment(Transaction<Object> txn, LogSegmentMetadata segment); @Override void updateLogSegment(Transaction<Object> txn, LogSegmentMetadata segment); @Override void process(WatchedEvent event); @Override Future<LogSegmentMetadata> getLogSegment(String logSegmentPath); @Override Future<List<String>> getLogSegmentNames(String logSegmentsPath); @Override @SuppressWarnings("unchecked") void processResult(int rc, String path, Object ctx, List<String> children, Stat stat); @Override void registerLogSegmentListener(String logSegmentsPath,
                                           LogSegmentNamesListener listener); @Override void unregisterLogSegmentListener(String logSegmentsPath,
                                             LogSegmentNamesListener listener); @Override void close();  }
@Test(timeout = 60000) public void testStoreMaxLogSegmentSequenceNumber() throws Exception { Transaction<Object> updateTxn = lsmStore.transaction(); Versioned<Long> value = new Versioned<Long>(999L, new ZkVersion(0)); final Promise<Version> result = new Promise<Version>(); lsmStore.storeMaxLogSegmentSequenceNumber(updateTxn, rootZkPath, value, new Transaction.OpListener<Version>() { @Override public void onCommit(Version r) { result.setValue(r); } @Override public void onAbort(Throwable t) { result.setException(t); } }); FutureUtils.result(updateTxn.execute()); assertEquals(1, ((ZkVersion) FutureUtils.result(result)).getZnodeVersion()); Stat stat = new Stat(); byte[] data = zkc.get().getData(rootZkPath, false, stat); assertEquals(999L, DLUtils.deserializeLogSegmentSequenceNumber(data)); assertEquals(1, stat.getVersion()); }