Skip to content

Commit 7ab119f

Browse files
committed
Address review comment
1 parent e5a302b commit 7ab119f

23 files changed

Lines changed: 50 additions & 757 deletions

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ build/
5050
*.dat
5151

5252
# Downloaded released BookKeeper versions (cached by CI, not committed)
53-
.released-versions/
53+
.released-versions/

bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Bookie.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,6 @@ void setExplicitLac(ByteBuf entry, WriteCallback writeCallback, Object ctx, byte
5757
// TODO: Shouldn't this be async?
5858
ByteBuf readEntry(long ledgerId, long entryId)
5959
throws IOException, NoLedgerException, BookieException;
60-
61-
/**
62-
* Read a ledger entry only when it can fit the provided bound.
63-
*
64-
* <p>{@code maxEntrySize} includes the 4-byte per-entry delimiter used by batched-read response framing.
65-
* Implementations return {@code null} when the entry exists but {@code entry.readableBytes() + 4}
66-
* exceeds {@code maxEntrySize}.
67-
*/
68-
ByteBuf readEntryIfFits(long ledgerId, long entryId, long maxEntrySize)
69-
throws IOException, NoLedgerException, BookieException;
7060
long readLastAddConfirmed(long ledgerId) throws IOException, BookieException;
7161
PrimitiveIterator.OfLong getListOfEntriesOfLedger(long ledgerId) throws IOException, NoLedgerException;
7262

@@ -137,4 +127,4 @@ public long getEntry() {
137127
}
138128
}
139129

140-
}
130+
}

bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BookieImpl.java

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,41 +1184,6 @@ public ByteBuf readEntry(long ledgerId, long entryId)
11841184
}
11851185
}
11861186

1187-
@Override
1188-
public ByteBuf readEntryIfFits(long ledgerId, long entryId, long maxEntrySize)
1189-
throws IOException, NoLedgerException, BookieException {
1190-
long requestNanos = MathUtils.nowInNano();
1191-
boolean recordStats = true;
1192-
boolean success = false;
1193-
int entrySize = 0;
1194-
try {
1195-
LedgerDescriptor handle = handles.getReadOnlyHandle(ledgerId);
1196-
log.trace().attr("entryId", entryId).attr("ledgerId", ledgerId).attr("maxEntrySize", maxEntrySize)
1197-
.log("Reading entry");
1198-
ByteBuf entry = handle.readEntryIfFits(entryId, maxEntrySize);
1199-
if (entry != null) {
1200-
entrySize = entry.readableBytes();
1201-
bookieStats.getReadBytes().addCount(entrySize);
1202-
} else {
1203-
recordStats = false;
1204-
return null;
1205-
}
1206-
success = true;
1207-
return entry;
1208-
} finally {
1209-
long elapsedNanos = MathUtils.elapsedNanos(requestNanos);
1210-
if (recordStats) {
1211-
if (success) {
1212-
bookieStats.getReadEntryStats().registerSuccessfulEvent(elapsedNanos, TimeUnit.NANOSECONDS);
1213-
bookieStats.getReadBytesStats().registerSuccessfulValue(entrySize);
1214-
} else {
1215-
bookieStats.getReadEntryStats().registerFailedEvent(elapsedNanos, TimeUnit.NANOSECONDS);
1216-
bookieStats.getReadBytesStats().registerFailedValue(entrySize);
1217-
}
1218-
}
1219-
}
1220-
}
1221-
12221187
public long readLastAddConfirmed(long ledgerId) throws IOException, BookieException {
12231188
LedgerDescriptor handle = handles.getReadOnlyHandle(ledgerId);
12241189
return handle.getLastAddConfirmed();

bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/DefaultEntryLogger.java

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -842,42 +842,6 @@ public ByteBuf readEntry(long location) throws IOException, Bookie.NoEntryExcept
842842
return internalReadEntry(-1L, -1L, location, false /* validateEntry */);
843843
}
844844

845-
@Override
846-
public ByteBuf readEntryIfFits(long ledgerId, long entryId, long entryLocation, long maxEntrySize)
847-
throws IOException, Bookie.NoEntryException {
848-
long entryLogId = logIdForOffset(entryLocation);
849-
long pos = posForOffset(entryLocation);
850-
851-
BufferedReadChannel fc = null;
852-
int entrySize;
853-
try {
854-
fc = getFCForEntryInternal(ledgerId, entryId, entryLogId, pos);
855-
856-
ByteBuf sizeBuff = readEntrySize(ledgerId, entryId, entryLogId, pos, fc);
857-
entrySize = sizeBuff.getInt(0);
858-
if (entrySize + Integer.BYTES > maxEntrySize) {
859-
// Oversized entries are treated as budget misses; a later unbounded read will validate them.
860-
return null;
861-
}
862-
validateEntry(ledgerId, entryId, entryLogId, pos, sizeBuff);
863-
} catch (EntryLookupException e) {
864-
throw new IOException("Bad entry read from log file id: " + entryLogId, e);
865-
}
866-
867-
ByteBuf data = allocator.buffer(entrySize, entrySize);
868-
int rc = readFromLogChannel(entryLogId, fc, data, pos);
869-
if (rc != entrySize) {
870-
ReferenceCountUtil.release(data);
871-
throw new IOException("Bad entry read from log file id: " + entryLogId,
872-
new EntryLookupException("Short read for " + ledgerId + "@"
873-
+ entryId + " in " + entryLogId + "@"
874-
+ pos + "(" + rc + "!=" + entrySize + ")"));
875-
}
876-
data.writerIndex(entrySize);
877-
return data;
878-
}
879-
880-
881845
private ByteBuf internalReadEntry(long ledgerId, long entryId, long location, boolean validateEntry)
882846
throws IOException, Bookie.NoEntryException {
883847
long entryLogId = logIdForOffset(location);

bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/InterleavedLedgerStorage.java

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -445,44 +445,6 @@ public ByteBuf getEntry(long ledgerId, long entryId) throws IOException {
445445
}
446446
}
447447

448-
@Override
449-
public ByteBuf getEntryIfFits(long ledgerId, long entryId, long maxEntrySize) throws IOException, BookieException {
450-
if (entryId == BookieProtocol.LAST_ADD_CONFIRMED) {
451-
entryId = ledgerCache.getLastEntry(ledgerId);
452-
}
453-
454-
long offset;
455-
long startTimeNanos = MathUtils.nowInNano();
456-
boolean success = false;
457-
try {
458-
offset = ledgerCache.getEntryOffset(ledgerId, entryId);
459-
if (offset == 0) {
460-
throw new Bookie.NoEntryException(ledgerId, entryId);
461-
}
462-
success = true;
463-
} finally {
464-
if (success) {
465-
getOffsetStats.registerSuccessfulEvent(MathUtils.elapsedNanos(startTimeNanos), TimeUnit.NANOSECONDS);
466-
} else {
467-
getOffsetStats.registerFailedEvent(MathUtils.elapsedNanos(startTimeNanos), TimeUnit.NANOSECONDS);
468-
}
469-
}
470-
471-
startTimeNanos = MathUtils.nowInNano();
472-
success = false;
473-
try {
474-
ByteBuf entry = entryLogger.readEntryIfFits(ledgerId, entryId, offset, maxEntrySize);
475-
success = true;
476-
return entry;
477-
} finally {
478-
if (success) {
479-
getEntryStats.registerSuccessfulEvent(MathUtils.elapsedNanos(startTimeNanos), TimeUnit.NANOSECONDS);
480-
} else {
481-
getEntryStats.registerFailedEvent(MathUtils.elapsedNanos(startTimeNanos), TimeUnit.NANOSECONDS);
482-
}
483-
}
484-
}
485-
486448
private void flushOrCheckpoint(boolean isCheckpointFlush)
487449
throws IOException {
488450

bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/LedgerDescriptor.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,6 @@ static ByteBuf createLedgerFenceEntry(Long ledgerId) {
7878
abstract long addEntry(ByteBuf entry) throws IOException, BookieException;
7979
abstract ByteBuf readEntry(long entryId) throws IOException, BookieException;
8080

81-
/**
82-
* Read an entry only when it fits within {@code maxEntrySize}.
83-
*
84-
* <p>{@code maxEntrySize} includes the 4-byte per-entry delimiter used in batched-read response framing,
85-
* so an exact fit is {@code entry.readableBytes() + 4 == maxEntrySize}.
86-
*/
87-
ByteBuf readEntryIfFits(long entryId, long maxEntrySize) throws IOException, BookieException {
88-
ByteBuf entry = readEntry(entryId);
89-
if (entry.readableBytes() + 4 > maxEntrySize) {
90-
entry.release();
91-
return null;
92-
}
93-
return entry;
94-
}
95-
9681
abstract long getLastAddConfirmed() throws IOException, BookieException;
9782
abstract boolean waitForLastAddConfirmedUpdate(long previousLAC,
9883
Watcher<LastAddConfirmedUpdateNotification> watcher)

bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/LedgerDescriptorImpl.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,6 @@ ByteBuf readEntry(long entryId) throws IOException, BookieException {
162162
return ledgerStorage.getEntry(ledgerId, entryId);
163163
}
164164

165-
@Override
166-
ByteBuf readEntryIfFits(long entryId, long maxEntrySize) throws IOException, BookieException {
167-
return ledgerStorage.getEntryIfFits(ledgerId, entryId, maxEntrySize);
168-
}
169-
170165
@Override
171166
long getLastAddConfirmed() throws IOException, BookieException {
172167
return ledgerStorage.getLastAddConfirmed(ledgerId);

bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/LedgerStorage.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -144,21 +144,6 @@ void initialize(ServerConfiguration conf,
144144
*/
145145
ByteBuf getEntry(long ledgerId, long entryId) throws IOException, BookieException;
146146

147-
/**
148-
* Read an entry from storage only if its serialized size, including the
149-
* 4-byte per-entry framing delimiter, is less than or equal to maxEntrySize.
150-
*
151-
* <p>Returns {@code null} when the entry exists but does not fit the supplied budget.
152-
*/
153-
default ByteBuf getEntryIfFits(long ledgerId, long entryId, long maxEntrySize) throws IOException, BookieException {
154-
ByteBuf entry = getEntry(ledgerId, entryId);
155-
if (entry.readableBytes() + Integer.BYTES > maxEntrySize) {
156-
entry.release();
157-
return null;
158-
}
159-
return entry;
160-
}
161-
162147
/**
163148
* Get last add confirmed.
164149
*

bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/SortedLedgerStorage.java

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -238,38 +238,6 @@ public ByteBuf getEntry(long ledgerId, long entryId) throws IOException, BookieE
238238
return buffToRet;
239239
}
240240

241-
@Override
242-
public ByteBuf getEntryIfFits(long ledgerId, long entryId, long maxEntrySize) throws IOException, BookieException {
243-
if (entryId == BookieProtocol.LAST_ADD_CONFIRMED) {
244-
EntryKeyValue kv = memTable.getLastEntry(ledgerId);
245-
if (kv != null) {
246-
ByteBuf entry = kv.getValueAsByteBuffer();
247-
if (entry.readableBytes() + Integer.BYTES > maxEntrySize) {
248-
entry.release();
249-
return null;
250-
}
251-
return entry;
252-
}
253-
return interleavedLedgerStorage.getEntryIfFits(ledgerId, entryId, maxEntrySize);
254-
}
255-
256-
try {
257-
return interleavedLedgerStorage.getEntryIfFits(ledgerId, entryId, maxEntrySize);
258-
} catch (Bookie.NoEntryException nee) {
259-
EntryKeyValue kv = memTable.getEntry(ledgerId, entryId);
260-
if (kv == null) {
261-
return interleavedLedgerStorage.getEntryIfFits(ledgerId, entryId, maxEntrySize);
262-
}
263-
264-
ByteBuf entry = kv.getValueAsByteBuffer();
265-
if (entry.readableBytes() + Integer.BYTES > maxEntrySize) {
266-
entry.release();
267-
return null;
268-
}
269-
return entry;
270-
}
271-
}
272-
273241
@Override
274242
public long getLastAddConfirmed(long ledgerId) throws IOException {
275243
return interleavedLedgerStorage.getLastAddConfirmed(ledgerId);

bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/EntryLogger.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,6 @@ ByteBuf readEntry(long entryLocation)
6767
ByteBuf readEntry(long ledgerId, long entryId, long entryLocation)
6868
throws IOException, NoEntryException;
6969

70-
/**
71-
* Read an entry only if its serialized size, including the 4-byte per-entry
72-
* framing delimiter, is less than or equal to maxEntrySize.
73-
*
74-
* <p>Returns {@code null} when the entry exists but does not fit the supplied budget.
75-
*/
76-
default ByteBuf readEntryIfFits(long ledgerId, long entryId, long entryLocation, long maxEntrySize)
77-
throws IOException, NoEntryException {
78-
ByteBuf entry = readEntry(ledgerId, entryId, entryLocation);
79-
if (entry.readableBytes() + Integer.BYTES > maxEntrySize) {
80-
entry.release();
81-
return null;
82-
}
83-
return entry;
84-
}
85-
8670
/**
8771
* Flush any outstanding writes to disk.
8872
*/

0 commit comments

Comments
 (0)