Skip to content

Commit

Permalink
Fix potential data loss
Browse files Browse the repository at this point in the history
  • Loading branch information
komamitsu committed Dec 17, 2023
1 parent 5376c37 commit 300d31e
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,9 @@ private RetentionBuffer prepareBuffer(String tag, int writeSize)

RetentionBuffer newBuffer = new RetentionBuffer(acquiredBuffer, System.currentTimeMillis());
if (retentionBuffer != null) {
retentionBuffer.getByteBuffer().flip();
newBuffer.getByteBuffer().put(retentionBuffer.getByteBuffer());
ByteBuffer buf = retentionBuffer.getByteBuffer().duplicate();
buf.flip();
newBuffer.getByteBuffer().put(buf);
bufferPool.returnBuffer(retentionBuffer.getByteBuffer());
}
LOG.trace("prepareBuffer(): allocate a new buffer. tag={}, buffer={}", tag, newBuffer);
Expand Down Expand Up @@ -334,8 +335,9 @@ private void moveRetentionBufferToFlushable(String tag, RetentionBuffer buffer)
{
try {
LOG.trace("moveRetentionBufferToFlushable(): tag={}, buffer={}", tag, buffer);
buffer.getByteBuffer().flip();
flushableBuffers.put(new TaggableBuffer(tag, buffer.getByteBuffer()));
ByteBuffer buf = buffer.getByteBuffer().duplicate();
buf.flip();
flushableBuffers.put(new TaggableBuffer(tag, buf));
retentionBuffers.put(tag, null);
}
catch (InterruptedException e) {
Expand Down

0 comments on commit 300d31e

Please sign in to comment.