forked from tronprotocol/java-tron
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(db): optimize old rewards withdrawal (tronprotocol#5406)
- Loading branch information
1 parent
db9f3be
commit 52b3327
Showing
24 changed files
with
969 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 69 additions & 1 deletion
70
chainbase/src/main/java/org/tron/core/db/common/iterator/DBIterator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,77 @@ | ||
package org.tron.core.db.common.iterator; | ||
|
||
import com.google.common.collect.Iterators; | ||
import com.google.common.collect.UnmodifiableIterator; | ||
import com.google.common.primitives.Bytes; | ||
import java.io.Closeable; | ||
import java.util.Iterator; | ||
import java.util.Map.Entry; | ||
import java.util.NoSuchElementException; | ||
|
||
public interface DBIterator extends Iterator<Entry<byte[], byte[]>>, Closeable { | ||
public interface DBIterator extends Iterator<Entry<byte[], byte[]>>, AutoCloseable, Closeable { | ||
|
||
void seek(byte[] key); | ||
|
||
void seekToFirst(); | ||
|
||
void seekToLast(); | ||
|
||
default UnmodifiableIterator<Entry<byte[], byte[]>> prefixQueryAfterThat | ||
(byte[] key, byte[] afterThat) { | ||
this.seek(afterThat == null ? key : afterThat); | ||
return Iterators.filter(this, entry -> Bytes.indexOf(entry.getKey(), key) == 0); | ||
} | ||
|
||
/** | ||
* An iterator is either positioned at a key/value pair, or | ||
* not valid. This method returns true iff the iterator is valid. | ||
* | ||
* REQUIRES: iterator not closed | ||
* | ||
* @throws IllegalStateException if the iterator is closed. | ||
* @return an iterator is either positioned at a key/value pair | ||
*/ | ||
boolean valid(); | ||
|
||
/** | ||
* The underlying storage for | ||
* the returned slice is valid only until the next modification of | ||
* the iterator. | ||
* | ||
* REQUIRES: valid() && !closed | ||
* | ||
* @throws IllegalStateException if the iterator is closed. | ||
* @throws NoSuchElementException if the iterator is not valid. | ||
* | ||
* @return the key for the current entry | ||
*/ | ||
byte[] getKey(); | ||
|
||
/** | ||
* The underlying storage for | ||
* the returned slice is valid only until the next modification of | ||
* the iterator. | ||
* | ||
* REQUIRES: valid() && !closed | ||
* | ||
* @throws IllegalStateException if the iterator is closed. | ||
* @throws NoSuchElementException if the iterator is not valid. | ||
* | ||
* @return the value for the current entry | ||
*/ | ||
byte[] getValue(); | ||
|
||
/** | ||
* @throws IllegalStateException if the iterator is closed. | ||
*/ | ||
void checkState(); | ||
|
||
/** | ||
* @throws NoSuchElementException if the iterator is not valid. | ||
*/ | ||
default void checkValid() { | ||
if (!valid()) { | ||
throw new NoSuchElementException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.