Skip to content
Closed
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 @@ -16,6 +16,7 @@
package com.google.cloud.bigtable.beam;

import com.google.cloud.bigtable.hbase.BigtableConfiguration;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
Expand Down Expand Up @@ -125,4 +126,17 @@ public void populateDisplayData(DisplayData.Builder builder) {
public CloudBigtableConfiguration getConfig() {
return config;
}

@Teardown
public void tearDown() {
// Close connection when DoFn is aborted.
if (connection != null) {
try {
connection.close();
} catch (IOException e) {
DOFN_LOG.info("Ignore an exception encountered while closing the connection", e);
}
connection = null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -685,11 +685,20 @@ public ByteKeyRangeTracker getRangeTracker() {

/** Closes the {@link ResultScanner}, {@link Table}, and {@link Connection}. */
@Override
public void close() throws IOException {
public void close() {
if (scanner != null) {
scanner.close();
scanner = null;
}

if (connection != null) {
try {
connection.close();
} catch (IOException ignored) {
}
connection = null;
}

long totalOps = getRowsReadCount();
long elapsedTimeMs = System.currentTimeMillis() - workStart;
long operationsPerSecond = elapsedTimeMs == 0 ? 0 : (totalOps * 1000 / elapsedTimeMs);
Expand Down Expand Up @@ -809,7 +818,7 @@ public void processElement(ProcessContext context) throws Exception {
mutationsCounter.inc();
}

/** Closes the {@link BufferedMutator} and {@link Connection}. */
/** Closes the {@link BufferedMutator}. */
@FinishBundle
public synchronized void finishBundle(@SuppressWarnings("unused") FinishBundleContext context)
throws Exception {
Expand Down