New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DL-124: Use Java8 Future rather than twitter Future #133
Conversation
- move proxy related class from protocol to proxy-protocol, changed client and service to proxy-client and proxy-service
Build finished. |
lastTruncationAttempt = writeHandler.purgeLogSegmentsOlderThanTimestamp(minTimestampToKeep); | ||
} | ||
} | ||
} | ||
|
||
private Future<BKLogSegmentWriter> asyncStartNewLogSegment(final BKLogWriteHandler writeHandler, | ||
private CompletableFuture<BKLogSegmentWriter> asyncStartNewLogSegment(final BKLogWriteHandler writeHandler, | ||
final long startTxId, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also do the code alignment change here.
return readInternal(numEntries, 0, TimeUnit.MILLISECONDS); | ||
} | ||
|
||
@Override | ||
public synchronized Future<List<LogRecordWithDLSN>> readBulk(int numEntries, | ||
public synchronized CompletableFuture<List<LogRecordWithDLSN>> readBulk(int numEntries, | ||
long waitTime, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also do the code alignment change here.
@@ -404,7 +392,7 @@ public String getStreamName() { | |||
* num entries to read | |||
* @return A promise that satisfied with a non-empty list of log records with their DLSN. | |||
*/ | |||
private synchronized Future<List<LogRecordWithDLSN>> readInternal(int numEntries, | |||
private synchronized CompletableFuture<List<LogRecordWithDLSN>> readInternal(int numEntries, | |||
long deadlineTime, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also do the code alignment change here.
@@ -206,7 +197,7 @@ private BKLogSegmentWriter getCachedLogSegmentWriter() throws WriteException { | |||
} | |||
} | |||
|
|||
private Future<BKLogSegmentWriter> getLogSegmentWriter(long firstTxid, | |||
private CompletableFuture<BKLogSegmentWriter> getLogSegmentWriter(long firstTxid, | |||
boolean bestEffort, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also do the code alignment change in this file, at line 201, 212, 242, 272,
} | ||
|
||
private Future<DLSN> getDLSNNotLessThanTxId(long fromTxnId, | ||
private CompletableFuture<DLSN> getDLSNNotLessThanTxId(long fromTxnId, | ||
final List<LogSegmentMetadata> segments) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also do the code alignment change in this file, also at line 565, 707, 838.
return asyncReadLastRecord(l, false, false, false); | ||
} | ||
|
||
public Future<LogRecordWithDLSN> asyncReadLastRecord(final LogSegmentMetadata l, | ||
public CompletableFuture<LogRecordWithDLSN> asyncReadLastRecord(final LogSegmentMetadata l, | ||
final boolean fence, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also do the code alignment change here.
} | ||
|
||
protected Future<BKLogSegmentWriter> asyncStartLogSegment(final long txId, | ||
protected CompletableFuture<BKLogSegmentWriter> asyncStartLogSegment(final long txId, | ||
final boolean bestEffort, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also do the code alignment change here.
} | ||
} | ||
}, null); | ||
return promise; | ||
} | ||
|
||
public Future<Void> deleteLedger(long lid, | ||
public CompletableFuture<Void> deleteLedger(long lid, | ||
final boolean ignoreNonExistentLedger) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also do the code alignment change here.
|
||
// Ledger configuration | ||
private final QuorumConfigProvider quorumConfigProvider; | ||
|
||
static Future<Versioned<byte[]>> getAndCreateAllocationData(final String allocatePath, | ||
static CompletableFuture<Versioned<byte[]>> getAndCreateAllocationData(final String allocatePath, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also do the code alignment change here, and also at line 128, 159.
KeeperException.Code.get(rc))); | ||
} | ||
} | ||
|
||
@Override | ||
public Future<Versioned<List<String>>> getLogSegmentNames(String logSegmentsPath, | ||
public CompletableFuture<Versioned<List<String>>> getLogSegmentNames(String logSegmentsPath, | ||
LogSegmentNamesListener listener) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also do the code alignment change here.
@@ -186,13 +185,13 @@ LedgerAllocator createLedgerAllocator(LogMetadataForWriter logMetadata, | |||
// | |||
|
|||
@Override | |||
public Future<LogSegmentEntryReader> openReader(LogSegmentMetadata segment, | |||
public CompletableFuture<LogSegmentEntryReader> openReader(LogSegmentMetadata segment, | |||
long startEntryId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also do the code alignment change here, also at line 244.
@@ -237,15 +227,13 @@ public DistributedLock createWriteLock(LogMetadataForWriter metadata) { | |||
// Create Read Lock | |||
// | |||
|
|||
private Future<Void> ensureReadLockPathExist(final LogMetadata logMetadata, | |||
private CompletableFuture<Void> ensureReadLockPathExist(final LogMetadata logMetadata, | |||
final String readLockPath) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also do the code alignment change here, and line 269, 312, 521, 572.
@@ -1088,9 +1063,9 @@ public String getActionName() { | |||
}); | |||
} | |||
|
|||
private Future<String> checkLockOwnerAndWaitIfPossible(final LockWatcher lockWatcher, | |||
private CompletableFuture<String> checkLockOwnerAndWaitIfPossible(final LockWatcher lockWatcher, | |||
final boolean wait) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also do the code alignment change here.
@@ -58,7 +57,7 @@ | |||
* @param startEntryId the start entry id | |||
* @return future represent the opened reader | |||
*/ | |||
Future<LogSegmentEntryReader> openReader(LogSegmentMetadata segment, | |||
CompletableFuture<LogSegmentEntryReader> openReader(LogSegmentMetadata segment, | |||
long startEntryId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also do the code alignment change here, and line 71
@@ -73,7 +72,7 @@ private String formatLogSegmentSequenceNumber(long logSegmentSeqNo) { | |||
} | |||
|
|||
@Override | |||
public Future<LogSegmentMetadata> changeSequenceNumber(LogSegmentMetadata segment, | |||
public CompletableFuture<LogSegmentMetadata> changeSequenceNumber(LogSegmentMetadata segment, | |||
long logSegmentSeqNo) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also do the code alignment change here.
@@ -59,7 +59,7 @@ | |||
* @param readerId the reader id used for lock | |||
* @return the read lock | |||
*/ | |||
Future<DistributedLock> createReadLock(LogMetadataForReader metadata, | |||
CompletableFuture<DistributedLock> createReadLock(LogMetadataForReader metadata, | |||
Optional<String> readerId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also do the code alignment change here, and line 83.
@@ -56,7 +56,7 @@ | |||
* ledger sequence number to change. | |||
* @return new log segment | |||
*/ | |||
Future<LogSegmentMetadata> changeSequenceNumber(LogSegmentMetadata segment, | |||
CompletableFuture<LogSegmentMetadata> changeSequenceNumber(LogSegmentMetadata segment, | |||
long logSegmentSeqNo); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also do the code alignment change here, and line 102.
} | ||
} | ||
}, null); | ||
return promise; | ||
} | ||
|
||
public static Future<Void> asyncClose(@Nullable AsyncCloseable closeable, | ||
public static CompletableFuture<Void> asyncClose(@Nullable AsyncCloseable closeable, | ||
boolean swallowIOException) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also do the code alignment change here, and line 573, 586.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, LGTM.
some small comments related to code alignment.
This changed so many places, thanks for the time.
Is there some way we can make migration easier? We're going to have to do a lot of translation to twitter futures when we integrate. Should we be thinking about some kind of adapter layer? |
distributedlog-benchmark/pom.xml
Outdated
@@ -27,12 +27,12 @@ | |||
<dependencies> | |||
<dependency> | |||
<groupId>org.apache.distributedlog</groupId> | |||
<artifactId>distributedlog-client</artifactId> | |||
<artifactId>distributedlog-proxy-client</artifactId> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change was based on #132. github doesn't allow pull request based on the other branch.
FutureUtils.cancel(acquireFuture); | ||
return null; | ||
final CompletableFuture<Void> threadAcquirePromise = new CompletableFuture<Void>(); | ||
threadAcquirePromise.whenComplete((value, cause) -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do i understand correctly java8 future doesn't really have the concept of interrupt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correctly, java8 future doesn't have the concept of interrupt. I try to simulate the similar thing.
+ BKException.getMessage(transmitResult), transmitResult); | ||
} | ||
|
||
public static <T> T ioResult(CompletableFuture<T> result) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not have a java8 version of FutureUtils?
seems weird to throw all of this into one file
@leighst : let's discuss this tomorrow face to face. I am thinking of a new api with java8 future that works for both core-library and proxy. that means the way to distinguish core and library is just the uri. we can have the old twitter-future based api wrapper over the new java8 future api. so it will be backward compatible. |
…re_to_java_future
@leighst - I pushed a new change:
So the old application can use distributedlog-core-twitter and keep the binary compatible. |
Let me know if this approach works for you. |
Build finished. |
1 similar comment
Build finished. |
Build finished. |
log4j.logger.org.apache.bookkeeper.util.SafeRunnable=INFO, Executors | ||
log4j.additivity.org.apache.distributedlog.util.MonitoredFuturePool=false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this will result in duplicate messages?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MonitoredFuturePool and MonitoredScheduledThreadPoolExecutor are already removed in this patch. because in Java8, you can configure a thread where the callbacks will be executed, there is no need for additional future pool, we just use the ordered scheduler.
Switch to use Java8 CompletableFuture, to reduce dependencies introduced by twitter future and make it more friendly to users (users don't think of using which version of scala).
This change is based on #132 . Gitsha ce0686e is the change to review.
The changes: