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

feat: flag future deletes and record a metrics #3534

Merged
merged 7 commits into from
Mar 15, 2022
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 @@ -18,6 +18,7 @@

import static com.google.cloud.bigtable.hbase.replication.metrics.HBaseToCloudBigtableReplicationMetrics.DROPPED_INCOMPATIBLE_MUTATION_METRIC_KEY;
import static com.google.cloud.bigtable.hbase.replication.metrics.HBaseToCloudBigtableReplicationMetrics.INCOMPATIBLE_MUTATION_METRIC_KEY;
import static com.google.cloud.bigtable.hbase.replication.metrics.HBaseToCloudBigtableReplicationMetrics.PUTS_IN_FUTURE_METRIC_KEY;

import com.google.cloud.bigtable.hbase.adapters.DeleteAdapter;
import com.google.cloud.bigtable.hbase.replication.metrics.MetricsExporter;
Expand Down Expand Up @@ -56,6 +57,10 @@ private void incrementIncompatibleMutations() {
metricsExporter.incCounters(INCOMPATIBLE_MUTATION_METRIC_KEY, 1);
}

private void incrementPutsInFutureMutations() {
metricsExporter.incCounters(PUTS_IN_FUTURE_METRIC_KEY, 1);
}

/**
* Creates an IncompatibleMutationAdapter with HBase configuration, MetricSource, and CBT
* connection.
Expand Down Expand Up @@ -101,6 +106,11 @@ public final List<Cell> adaptIncompatibleMutations(BigtableWALEntry walEntry) {
Cell cell = cellsToAdapt.get(index);
// All puts are valid.
if (cell.getTypeByte() == KeyValue.Type.Put.getCode()) {
// flag if put is issued for future timestamp
// do not log as we might fill up disk space due condition being true from clock skew
if (cell.getTimestamp() > walEntry.getWalWriteTime()) {
incrementPutsInFutureMutations();
}
returnedCells.add(cell);
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ private HBaseToCloudBigtableReplicationMetrics() {}
public static final String INCOMPATIBLE_MUTATION_METRIC_KEY = "bigtableIncompatibleMutations";
public static final String DROPPED_INCOMPATIBLE_MUTATION_METRIC_KEY =
"bigtableDroppedIncompatibleMutations";
public static final String PUTS_IN_FUTURE_METRIC_KEY = "bigtablePutsInFutureMutations";
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@

import static com.google.cloud.bigtable.hbase.replication.metrics.HBaseToCloudBigtableReplicationMetrics.DROPPED_INCOMPATIBLE_MUTATION_METRIC_KEY;
import static com.google.cloud.bigtable.hbase.replication.metrics.HBaseToCloudBigtableReplicationMetrics.INCOMPATIBLE_MUTATION_METRIC_KEY;
import static com.google.cloud.bigtable.hbase.replication.metrics.HBaseToCloudBigtableReplicationMetrics.PUTS_IN_FUTURE_METRIC_KEY;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.verifyNoMoreInteractions;

import com.google.cloud.bigtable.hbase.replication.metrics.MetricsExporter;
import java.nio.charset.StandardCharsets;
Expand All @@ -35,6 +37,7 @@
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.KeyValue.Type;
import org.apache.hadoop.hbase.client.Connection;
import org.junit.After;
import org.junit.Assert;
Expand Down Expand Up @@ -226,4 +229,23 @@ public void testIncompatibleDeletesAreDropped() {
verify(metricsExporter, times(1)).incCounters(INCOMPATIBLE_MUTATION_METRIC_KEY, 1);
verify(metricsExporter, times(1)).incCounters(DROPPED_INCOMPATIBLE_MUTATION_METRIC_KEY, 1);
}

@Test
public void testFuturePutAreFlagged() {
ArrayList<Cell> walEntryCells = new ArrayList<>();
Cell put1 = new KeyValue(rowKey, cf, qual, 900, Type.Put);
Cell put2 = new KeyValue(rowKey, cf, qual, 1005L, Type.Put);
walEntryCells.add(put1);
walEntryCells.add(put2);
BigtableWALEntry walEntry = new BigtableWALEntry(1000L, walEntryCells, tableName);

Assert.assertEquals(
Arrays.asList(put1, put2),
incompatibleMutationAdapter.adaptIncompatibleMutations(walEntry));

verify(metricsExporter).incCounters(INCOMPATIBLE_MUTATION_METRIC_KEY, 0);
verify(metricsExporter).incCounters(DROPPED_INCOMPATIBLE_MUTATION_METRIC_KEY, 0);
verify(metricsExporter, times(1)).incCounters(PUTS_IN_FUTURE_METRIC_KEY, 1);
verifyNoMoreInteractions(metricsExporter);
}
}