private void sync() throws IOException { // writes out pending entries to the HLog TransactionLogWriter tmpWriter = null; long latestSeq = 0; int entryCount = 0; synchronized (this) { if (closed) { return; } // prevent writer being dereferenced tmpWriter = writer; List<Entry> currentPending = getPendingWrites(); if (!currentPending.isEmpty()) { tmpWriter.commitMarker(currentPending.size()); } // write out all accumulated entries to log. for (Entry e : currentPending) { tmpWriter.append(e); entryCount++; latestSeq = Math.max(latestSeq, e.getKey().get()); } } long lastSynced = syncedUpTo.get(); // someone else might have already synced our edits, avoid double syncing if (lastSynced < latestSeq) { tmpWriter.sync(); metricsCollector.histogram("wal.sync.size", entryCount); syncedUpTo.compareAndSet(lastSynced, latestSeq); } }
private void sync() throws IOException { // writes out pending entries to the HLog TransactionLogWriter tmpWriter = null; long latestSeq = 0; int entryCount = 0; synchronized (this) { if (closed) { return; } // prevent writer being dereferenced tmpWriter = writer; List<Entry> currentPending = getPendingWrites(); if (!currentPending.isEmpty()) { tmpWriter.commitMarker(currentPending.size()); } // write out all accumulated entries to log. for (Entry e : currentPending) { tmpWriter.append(e); entryCount++; latestSeq = Math.max(latestSeq, e.getKey().get()); } } long lastSynced = syncedUpTo.get(); // someone else might have already synced our edits, avoid double syncing if (lastSynced < latestSeq) { tmpWriter.sync(); metricsCollector.histogram("wal.sync.size", entryCount); syncedUpTo.compareAndSet(lastSynced, latestSeq); } }
writer.append(entry.getKey(), entry.getEdit()); writer.append(entry.getKey(), entry.getEdit()); edits.get(totalCount - 1)); if (isComplete) { writer.append(entry.getKey(), entry.getEdit()); } else { byte[] bytes = Longs.toByteArray(entry.getKey().get()); writer.appendRaw(bytes, 0, bytes.length, new SequenceFile.ValueBytes() { @Override
@Override public void append(Entry entry) throws IOException { internalWriter.append(entry.getKey(), entry.getEdit()); }
@Override public TransactionEdit next(TransactionEdit reuse) throws IOException { try { reuseEntry.getKey().readFields(in); reuse.readFields(in); } catch (EOFException eofe) { // signal end of file by returning null return null; } return reuse; }
@Override public void append(Entry entry) throws IOException { internalWriter.append(entry.getKey(), entry.getEdit()); }
@Override public TransactionEdit next(TransactionEdit reuse) throws IOException { try { reuseEntry.getKey().readFields(in); reuse.readFields(in); } catch (EOFException eofe) { // signal end of file by returning null return null; } return reuse; }