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

Allow table cache to be bypassed in WrappedAccumuloClient (#2359) #14

Merged
merged 1 commit into from
May 29, 2024
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 @@ -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;
}
}
Loading