/** * Write log records to the stream. * * @param record operation */ @Override public void write(LogRecord record) throws IOException { getLedgerWriter(record.getTransactionId(), false).write(record); }
@Override public void onSuccess(DLSN dlsn) { recordSetWriter.completeTransmit( dlsn.getLogSegmentSequenceNo(), dlsn.getEntryId(), dlsn.getSlotId()); } })
synchronized private Future<DLSN> writeControlLogRecord() throws BKTransmitException, WriteException, InvalidEnvelopedEntryException, LockingException, LogRecordTooLongException { LogRecord controlRec = new LogRecord(lastTxId, DistributedLogConstants.CONTROL_RECORD_CONTENT); controlRec.setControl(); return writeControlLogRecord(controlRec); }
@Test(timeout = 60000, expected = BKException.BKBookieHandleNotAvailableException.class) public void testOpenLedgerWhenBkcClosed() throws Exception { BookKeeperClient newBkc = BookKeeperClientBuilder.newBuilder().name("newBkc") .zkc(zkc).ledgersPath(ledgersPath).dlConfig(conf).build(); LedgerHandleCache cache = LedgerHandleCache.newBuilder().bkc(newBkc).conf(conf).build(); // closed the bkc newBkc.close(); // open ledger after bkc closed. cache.openLedger(new LogSegmentMetadata.LogSegmentMetadataBuilder("", 2, 1, 1).setRegionId(1).build(), false); }
static long getNumberofLogRecords(DistributedLogManager bkdlm, long startTxId) throws IOException { long numLogRecs = 0; LogReader reader = bkdlm.getInputStream(startTxId); LogRecord record = reader.readNext(false); while (null != record) { numLogRecs++; verifyLogRecord(record); record = reader.readNext(false); } reader.close(); return numLogRecs; }
public long getLastTxId(boolean recover, boolean includeEndOfStream) throws IOException { checkLogStreamExists(); return getLastLogRecord(recover, includeEndOfStream).getTransactionId(); }
static void setTruncationStatus(ZooKeeperClient zkc, LogSegmentMetadata l, TruncationStatus status) throws Exception { LogSegmentMetadata newSegment = l.mutator().setTruncationStatus(status).build(); DLMTestUtil.updateSegmentMetadata(zkc, newSegment); }
static void updateCompletionTime(ZooKeeperClient zkc, LogSegmentMetadata l, long completionTime) throws Exception { LogSegmentMetadata newSegment = l.mutator().setCompletionTime(completionTime).build(); DLMTestUtil.updateSegmentMetadata(zkc, newSegment); }
public static LogRecordWithDLSN getLogRecordWithDLSNInstance(DLSN dlsn, long txId, boolean isControlRecord) { LogRecordWithDLSN record = new LogRecordWithDLSN(dlsn, txId, generatePayload(txId), 1L); record.setPositionWithinLogSegment((int)txId + 1); if (isControlRecord) { record.setControl(); } return record; }
private BookKeeperClient getBookKeeperClient(com.twitter.distributedlog.DistributedLogManagerFactory factory) { DistributedLogNamespace namespace = factory.getNamespace(); assert(namespace instanceof BKDistributedLogNamespace); return ((BKDistributedLogNamespace) namespace).getReaderBKC(); }
public static void generateCompletedLogSegments(DistributedLogManager manager, DistributedLogConfiguration conf, long numCompletedSegments, long segmentSize) throws Exception { BKDistributedLogManager dlm = (BKDistributedLogManager) manager; long txid = 1L; for (long i = 0; i < numCompletedSegments; i++) { BKSyncLogWriter writer = dlm.startLogSegmentNonPartitioned(); for (long j = 1; j <= segmentSize; j++) { writer.write(DLMTestUtil.getLogRecordInstance(txid++)); } writer.closeAndComplete(); } }
private ZooKeeperClient getZooKeeperClient(com.twitter.distributedlog.DistributedLogManagerFactory factory) { DistributedLogNamespace namespace = factory.getNamespace(); assert(namespace instanceof BKDistributedLogNamespace); return ((BKDistributedLogNamespace) namespace).getSharedWriterZKCForDL(); }
/** * Write a log record as control record. The method will be used by Monitor Service to enforce a new inprogress segment. * * @param record * log record * @return future of the write */ public Future<DLSN> writeControlRecord(final LogRecord record) { record.setControl(); return write(record); }
@SuppressWarnings("deprecation") protected LogSegmentMetadataStore getLogSegmentMetadataStore(DistributedLogManagerFactory factory) { DistributedLogNamespace namespace = factory.getNamespace(); assert(namespace instanceof BKDistributedLogNamespace); return ((BKDistributedLogNamespace) namespace).getWriterSegmentMetadataStore(); }
protected LogSegmentMetadataStoreUpdater(DistributedLogConfiguration conf, LogSegmentMetadataStore metadataStore) { this.metadataStore = metadataStore; this.metadataVersion = LogSegmentMetadata.LogSegmentMetadataVersion.of(conf.getDLLedgerMetadataLayoutVersion()); }
@Override public void onFailure(Throwable cause) { super.onFailure(cause); // error out pending requests. errorOutPendingRequestsAndWriter(cause); } }
protected BKLogWriteHandler getWriteHandler() throws IOException { BKLogWriteHandler writeHandler = createAndCacheWriteHandler(); writeHandler.checkMetadataException(); return writeHandler; }
@Override public void onSuccess(DLSN dlsn) { recordSetWriter.completeTransmit( dlsn.getLogSegmentSequenceNo(), dlsn.getEntryId(), dlsn.getSlotId()); }
@SuppressWarnings("deprecation") protected BookKeeperClient getBookKeeperClient(DistributedLogManagerFactory factory) throws Exception { DistributedLogNamespace namespace = factory.getNamespace(); assert(namespace instanceof BKDistributedLogNamespace); return ((BKDistributedLogNamespace) namespace).getReaderBKC(); }
@SuppressWarnings("deprecation") protected ZooKeeperClient getZooKeeperClient(DistributedLogManagerFactory factory) throws Exception { DistributedLogNamespace namespace = factory.getNamespace(); assert(namespace instanceof BKDistributedLogNamespace); return ((BKDistributedLogNamespace) namespace).getSharedWriterZKCForDL(); }