Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/main/java/com/baidu/fsg/uid/buffer/BufferPaddingExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,27 @@ public void paddingBuffer() {
}

// fill the rest slots until to catch the cursor
putBuffer();
}
/**
* Padding buffer fill the slots until to catch the cursor
*/
public Boolean booleanPaddingBuffer() {
LOGGER.info("Ready to padding buffer lastSecond:{}. {}", lastSecond.get(), ringBuffer);

// is still running
if (!running.compareAndSet(false, true)) {
LOGGER.info("Padding buffer is still running. {}", ringBuffer);
return false;
}

// fill the rest slots until to catch the cursor
putBuffer();
return true;
}

private void putBuffer() {

boolean isFullRingBuffer = false;
while (!isFullRingBuffer) {
List<Long> uidList = uidProvider.provide(lastSecond.incrementAndGet());
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/com/baidu/fsg/uid/buffer/RingBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,16 @@ public long take() {

// cursor catch the tail, means that there is no more available UID to take
if (nextCursor == currentCursor) {
rejectedTakeHandler.rejectTakeBuffer(this);
Boolean running = false;
while (!running) {
running = bufferPaddingExecutor.booleanPaddingBuffer();
}
nextCursor = cursor.updateAndGet(old -> old == tail.get() ? old : old + 1);

if (nextCursor == currentCursor) {
rejectedTakeHandler.rejectTakeBuffer(this);
}
}

// 1. check next slot flag is CAN_TAKE_FLAG
int nextCursorIndex = calSlotIndex(nextCursor);
Assert.isTrue(flags[nextCursorIndex].get() == CAN_TAKE_FLAG, "Curosr not in can take status");
Expand Down