Skip to content
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

fix: ConcurrentBufferedMutator waits for both flushes to finish before closing #161

Merged
merged 1 commit into from
Dec 2, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public void run() {
// connection lasted no longer than 3 seconds, but we also need to check that it waited at least
// `timeoutMillis`. `closeDuration` is strictly greater than timeout because it includes some
// overhead, but `timeoutMillis` >> expected overhead, thus false-positives are unlikely.
assertThat(closeDuration).isGreaterThan(timeoutMillis);
assertThat(closeDuration).isAtLeast(timeoutMillis);
assertThat(c.getPrimaryConnection().isClosed()).isTrue();
assertThat(c.getSecondaryConnection().isClosed()).isFalse();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ protected void handleSecondaryException(RetriesExhaustedWithDetailsException e)
}
}

@Override
protected void flushBufferedMutatorBeforeClosing()
throws ExecutionException, InterruptedException {
scheduleFlushAll().bothFlushesFinished.get();
}

@Override
protected FlushFutures scheduleFlushScoped(
final List<List<? extends Mutation>> dataToFlush, FlushFutures previousFlushFutures) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ protected final FlushFutures scheduleFlushAll() {
return this.flushSerializer.scheduleFlushAll();
}

protected abstract void flushBufferedMutatorBeforeClosing()
throws ExecutionException, InterruptedException;

@Override
public final void close() throws IOException {
try (Scope scope =
Expand All @@ -225,7 +228,7 @@ public final void close() throws IOException {
List<IOException> exceptions = new ArrayList<>();

try {
scheduleFlushAll().secondaryFlushFinished.get();
flushBufferedMutatorBeforeClosing();
this.ongoingFlushesCounter.decrementReferenceCount();
this.ongoingFlushesCounter.getOnLastReferenceClosed().get();
} catch (InterruptedException | ExecutionException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,12 @@ protected void handleSecondaryException(RetriesExhaustedWithDetailsException e)
reportWriteErrors(e);
}

@Override
protected void flushBufferedMutatorBeforeClosing()
throws ExecutionException, InterruptedException {
scheduleFlushAll().secondaryFlushFinished.get();
}

@Override
protected FlushFutures scheduleFlushScoped(
final List<Entry> dataToFlush, final FlushFutures previousFlushFutures) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,13 @@ limitations under the License.
<scope>test</scope>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>com.google.cloud.bigtable</groupId>
<artifactId>bigtable-hbase-mirroring-client-1.x</artifactId>
<version>2.0.0-alpha2-SNAPSHOT</version> <!-- {x-version-update:bigtable-client-parent:current} -->
<scope>test</scope>
<type>test-jar</type>
</dependency>

<!-- Needed by MiniHBaseCluster -->
<dependency>
Expand Down