Skip to content

Commit 50eb122

Browse files
committed
fix: change leveldb method name .
1 parent f6d2232 commit 50eb122

3 files changed

Lines changed: 38 additions & 7 deletions

File tree

‎src/main/java/org/tron/common/storage/leveldb/LevelDbDataSourceImpl.java‎

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,12 @@ public Set<byte[]> allValues() {
252252
}
253253
}
254254

255-
public Set<byte[]> getLimitNumber(byte[] startNumber, long getLimit) {
255+
public Set<byte[]> getSeekKeyLimitNext(byte[] startKey, long getLimit) {
256256
resetDbLock.readLock().lock();
257257
try (DBIterator iterator = database.iterator()) {
258258
Set<byte[]> result = new HashSet<>();
259259
long i = 0;
260-
for (iterator.seek(startNumber); iterator.hasNext() && i++ < getLimit; iterator.next()) {
260+
for (iterator.seek(startKey); iterator.hasNext() && i++ < getLimit; iterator.next()) {
261261
result.add(iterator.peekNext().getValue());
262262
}
263263
return result;
@@ -268,10 +268,26 @@ public Set<byte[]> getLimitNumber(byte[] startNumber, long getLimit) {
268268
}
269269
}
270270

271-
public byte[] getByNumKey(byte[] numBytes) {
271+
public Set<byte[]> getSeekKeyLimitPrev(byte[] startKey, long getLimit) {
272272
resetDbLock.readLock().lock();
273273
try (DBIterator iterator = database.iterator()) {
274-
iterator.seek(numBytes);
274+
Set<byte[]> result = new HashSet<>();
275+
long i = 0;
276+
for (iterator.seek(startKey); iterator.hasPrev() && i++ < getLimit; iterator.prev()) {
277+
result.add(iterator.peekPrev().getValue());
278+
}
279+
return result;
280+
} catch (IOException e) {
281+
throw new RuntimeException(e);
282+
} finally {
283+
resetDbLock.readLock().unlock();
284+
}
285+
}
286+
287+
public byte[] getBySeekKeyNext(byte[] keyBytes) {
288+
resetDbLock.readLock().lock();
289+
try (DBIterator iterator = database.iterator()) {
290+
iterator.seek(keyBytes);
275291
if (iterator.hasNext()) {
276292
return iterator.peekNext().getValue();
277293
}
@@ -283,6 +299,21 @@ public byte[] getByNumKey(byte[] numBytes) {
283299
}
284300
}
285301

302+
public byte[] getBySeekKeyPrev(byte[] keyBytes) {
303+
resetDbLock.readLock().lock();
304+
try (DBIterator iterator = database.iterator()) {
305+
iterator.seek(keyBytes);
306+
if (iterator.hasPrev()) {
307+
return iterator.peekPrev().getValue();
308+
}
309+
return null;
310+
} catch (IOException e) {
311+
throw new RuntimeException(e);
312+
} finally {
313+
resetDbLock.readLock().unlock();
314+
}
315+
}
316+
286317
@Override
287318
public long getTotal() throws RuntimeException {
288319
resetDbLock.readLock().lock();

‎src/main/java/org/tron/core/db/BlockStore.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public BlockCapsule get(byte[] key) throws ItemNotFoundException, BadItemExcepti
103103

104104
public BlockCapsule getByNum(long blockNum) throws ItemNotFoundException, BadItemException {
105105
BlockId blockId = new BlockId(Sha256Hash.ZERO_HASH, blockNum);
106-
byte[] value = dbSource.getByNumKey(blockId.getBytes());
106+
byte[] value = dbSource.getBySeekKeyNext(blockId.getBytes());
107107
if (ArrayUtils.isEmpty(value)) {
108108
throw new ItemNotFoundException();
109109
}
@@ -113,7 +113,7 @@ public BlockCapsule getByNum(long blockNum) throws ItemNotFoundException, BadIte
113113
public List<BlockCapsule> getLimitNumber(long startNumber, long limit)
114114
throws ItemNotFoundException, BadItemException {
115115
BlockId startBlockId = new BlockId(Sha256Hash.ZERO_HASH, startNumber);
116-
return dbSource.getLimitNumber(startBlockId.getBytes(), limit)
116+
return dbSource.getSeekKeyLimitNext(startBlockId.getBytes(), limit)
117117
.stream().map(bytes -> {
118118
try {
119119
return new BlockCapsule(bytes);

‎src/main/java/org/tron/core/db/TransactionStore.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public TransactionCapsule get(byte[] key) {
2929
}
3030

3131
public List<TransactionCapsule> getLimitNumber(byte[] startTransactionId, long limit) {
32-
return dbSource.getLimitNumber(startTransactionId, limit)
32+
return dbSource.getSeekKeyLimitNext(startTransactionId, limit)
3333
.stream().map(bytes -> {
3434
return new TransactionCapsule(bytes);
3535
})

0 commit comments

Comments
 (0)