Skip to content

Commit

Permalink
Allow table cache to be bypassed in WrappedAccumuloClient (#4, DW #2359)
Browse files Browse the repository at this point in the history
  • Loading branch information
keith-ratcliffe committed May 28, 2024
1 parent bfb8e26 commit 59f998a
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,13 @@ public void updateClientConfig(AccumuloClientConfiguration clientConfig) {

@Override
public BatchScanner createBatchScanner(String tableName, Authorizations authorizations, int numQueryThreads) throws TableNotFoundException {
return createBatchScanner(tableName, authorizations, numQueryThreads, false);
}

public BatchScanner createBatchScanner(String tableName, Authorizations authorizations, int numQueryThreads, boolean skipCache)
throws TableNotFoundException {
BatchScannerDelegate delegate;
if (mock.tableOperations().list().contains(tableName)) {
if (!skipCache && mock.tableOperations().list().contains(tableName)) {
if (log.isTraceEnabled()) {
log.trace("Creating mock batch scanner for table: " + tableName);
}
Expand All @@ -82,8 +87,12 @@ public BatchScanner createBatchScanner(String tableName, Authorizations authoriz

@Override
public BatchScanner createBatchScanner(String tableName, Authorizations authorizations) throws TableNotFoundException {
return createBatchScanner(tableName, authorizations, false);
}

public BatchScanner createBatchScanner(String tableName, Authorizations authorizations, boolean skipCache) throws TableNotFoundException {
BatchScannerDelegate delegate;
if (mock.tableOperations().list().contains(tableName)) {
if (!skipCache && mock.tableOperations().list().contains(tableName)) {
if (log.isTraceEnabled()) {
log.trace("Creating mock batch scanner for table: " + tableName);
}
Expand All @@ -107,8 +116,12 @@ public BatchScanner createBatchScanner(String tableName, Authorizations authoriz

@Override
public BatchScanner createBatchScanner(String tableName) throws TableNotFoundException, AccumuloSecurityException, AccumuloException {
return createBatchScanner(tableName, false);
}

public BatchScanner createBatchScanner(String tableName, boolean skipCache) throws TableNotFoundException, AccumuloSecurityException, AccumuloException {
BatchScannerDelegate delegate;
if (mock.tableOperations().list().contains(tableName)) {
if (!skipCache && mock.tableOperations().list().contains(tableName)) {
if (log.isTraceEnabled()) {
log.trace("Creating mock batch scanner for table: " + tableName);
}
Expand Down Expand Up @@ -179,8 +192,12 @@ public ConditionalWriter createConditionalWriter(String tableName) throws TableN

@Override
public Scanner createScanner(String tableName, Authorizations authorizations) throws TableNotFoundException {
return createScanner(tableName, authorizations, false);
}

public Scanner createScanner(String tableName, Authorizations authorizations, boolean skipCache) throws TableNotFoundException {
ScannerDelegate delegate;
if (mock.tableOperations().list().contains(tableName)) {
if (!skipCache && mock.tableOperations().list().contains(tableName)) {
if (log.isTraceEnabled()) {
log.trace("Creating mock scanner for table: " + tableName);
}
Expand All @@ -203,8 +220,12 @@ public Scanner createScanner(String tableName, Authorizations authorizations) th

@Override
public Scanner createScanner(String tableName) throws TableNotFoundException, AccumuloSecurityException, AccumuloException {
return createScanner(tableName, false);
}

public Scanner createScanner(String tableName, boolean skipCache) throws TableNotFoundException, AccumuloSecurityException, AccumuloException {
Scanner delegate;
if (mock.tableOperations().list().contains(tableName)) {
if (!skipCache && mock.tableOperations().list().contains(tableName)) {
if (log.isTraceEnabled()) {
log.trace("Creating mock batch scanner for table: " + tableName);
}
Expand Down Expand Up @@ -282,5 +303,4 @@ public long getScanBatchTimeoutSeconds() {
public void setScanBatchTimeoutSeconds(long scanBatchTimeoutSeconds) {
this.scanBatchTimeoutSeconds = scanBatchTimeoutSeconds;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package datawave.webservice.common.connection;

import java.util.Collection;
import java.util.Iterator;

import org.apache.accumulo.core.client.BatchScanner;
import org.apache.accumulo.core.client.Scanner;
import org.apache.accumulo.core.client.TableNotFoundException;
import org.apache.accumulo.core.security.Authorizations;

import datawave.security.util.AuthorizationsMinimizer;
import datawave.security.util.ScannerHelper;

/**
* Scanner factory for {@link WrappedAccumuloClient} that allows the table cache to be bypassed, if desired
*/
public class WrappedScannerHelper extends ScannerHelper {

public static Scanner createScanner(WrappedAccumuloClient connector, String tableName, Collection<Authorizations> authorizations, boolean skipCache)
throws TableNotFoundException {
if (authorizations == null || authorizations.isEmpty()) {
throw new IllegalArgumentException("Authorizations must not be empty.");
}
Iterator<Authorizations> iter = AuthorizationsMinimizer.minimize(authorizations).iterator();
Scanner scanner = connector.createScanner(tableName, iter.next(), skipCache);
addVisibilityFilters(iter, scanner);
return scanner;
}

public static BatchScanner createBatchScanner(WrappedAccumuloClient connector, String tableName, Collection<Authorizations> authorizations,
int numQueryThreads, boolean skipCache) throws TableNotFoundException {
if (authorizations == null || authorizations.isEmpty()) {
throw new IllegalArgumentException("Authorizations must not be empty.");
}
Iterator<Authorizations> iter = AuthorizationsMinimizer.minimize(authorizations).iterator();
BatchScanner batchScanner = connector.createBatchScanner(tableName, iter.next(), numQueryThreads, skipCache);
addVisibilityFilters(iter, batchScanner);
return batchScanner;
}
}

0 comments on commit 59f998a

Please sign in to comment.