use of org.apache.accumulo.server.log.WalStateManager in project accumulo by apache.
the class VolumeIT method verifyVolumesUsed.
private void verifyVolumesUsed(String tableName, boolean shouldExist, Path... paths) throws Exception {
Connector conn = getConnector();
List<String> expected = new ArrayList<>();
for (int i = 0; i < 100; i++) {
String row = String.format("%06d", i * 100 + 3);
expected.add(row + ":cf1:cq1:1");
}
if (!conn.tableOperations().exists(tableName)) {
Assert.assertFalse(shouldExist);
writeData(tableName, conn);
verifyData(expected, conn.createScanner(tableName, Authorizations.EMPTY));
conn.tableOperations().flush(tableName, null, null, true);
}
verifyData(expected, conn.createScanner(tableName, Authorizations.EMPTY));
Table.ID tableId = Table.ID.of(conn.tableOperations().tableIdMap().get(tableName));
try (Scanner metaScanner = conn.createScanner(MetadataTable.NAME, Authorizations.EMPTY)) {
MetadataSchema.TabletsSection.ServerColumnFamily.DIRECTORY_COLUMN.fetch(metaScanner);
metaScanner.fetchColumnFamily(MetadataSchema.TabletsSection.DataFileColumnFamily.NAME);
metaScanner.setRange(new KeyExtent(tableId, null, null).toMetadataRange());
int[] counts = new int[paths.length];
outer: for (Entry<Key, Value> entry : metaScanner) {
String cf = entry.getKey().getColumnFamily().toString();
String cq = entry.getKey().getColumnQualifier().toString();
String path;
if (cf.equals(MetadataSchema.TabletsSection.DataFileColumnFamily.NAME.toString()))
path = cq;
else
path = entry.getValue().toString();
for (int i = 0; i < paths.length; i++) {
if (path.startsWith(paths[i].toString())) {
counts[i]++;
continue outer;
}
}
Assert.fail("Unexpected volume " + path);
}
// keep retrying until WAL state information in ZooKeeper stabilizes or until test times out
retry: while (true) {
Instance i = conn.getInstance();
ZooReaderWriter zk = new ZooReaderWriter(i.getZooKeepers(), i.getZooKeepersSessionTimeOut(), "");
WalStateManager wals = new WalStateManager(i, zk);
try {
outer: for (Entry<Path, WalState> entry : wals.getAllState().entrySet()) {
for (Path path : paths) {
if (entry.getKey().toString().startsWith(path.toString())) {
continue outer;
}
}
log.warn("Unexpected volume " + entry.getKey() + " (" + entry.getValue() + ")");
continue retry;
}
} catch (WalMarkerException e) {
Throwable cause = e.getCause();
if (cause instanceof NoNodeException) {
// ignore WALs being cleaned up
continue retry;
}
throw e;
}
break;
}
// if a volume is chosen randomly for each tablet, then the probability that a volume will not be chosen for any tablet is ((num_volumes -
// 1)/num_volumes)^num_tablets. For 100 tablets and 3 volumes the probability that only 2 volumes would be chosen is 2.46e-18
int sum = 0;
for (int count : counts) {
Assert.assertTrue(count > 0);
sum += count;
}
Assert.assertEquals(200, sum);
}
}
use of org.apache.accumulo.server.log.WalStateManager in project accumulo by apache.
the class UnusedWALIT method getWALCount.
private int getWALCount(Instance i, ZooReaderWriter zk) throws Exception {
WalStateManager wals = new WalStateManager(i, zk);
int result = 0;
for (Entry<TServerInstance, List<UUID>> entry : wals.getAllMarkers().entrySet()) {
result += entry.getValue().size();
}
return result;
}
use of org.apache.accumulo.server.log.WalStateManager in project accumulo by apache.
the class ReplicationIT method getLogs.
private Multimap<String, Table.ID> getLogs(Connector conn) throws Exception {
// Map of server to tableId
Multimap<TServerInstance, String> serverToTableID = HashMultimap.create();
try (Scanner scanner = conn.createScanner(MetadataTable.NAME, Authorizations.EMPTY)) {
scanner.setRange(MetadataSchema.TabletsSection.getRange());
scanner.fetchColumnFamily(MetadataSchema.TabletsSection.CurrentLocationColumnFamily.NAME);
for (Entry<Key, Value> entry : scanner) {
TServerInstance key = new TServerInstance(entry.getValue(), entry.getKey().getColumnQualifier());
byte[] tableId = KeyExtent.tableOfMetadataRow(entry.getKey().getRow());
serverToTableID.put(key, new String(tableId, UTF_8));
}
// Map of logs to tableId
Multimap<String, Table.ID> logs = HashMultimap.create();
Instance i = conn.getInstance();
ZooReaderWriter zk = new ZooReaderWriter(i.getZooKeepers(), i.getZooKeepersSessionTimeOut(), "");
WalStateManager wals = new WalStateManager(conn.getInstance(), zk);
for (Entry<TServerInstance, List<UUID>> entry : wals.getAllMarkers().entrySet()) {
for (UUID id : entry.getValue()) {
Pair<WalState, Path> state = wals.state(entry.getKey(), id);
for (String tableId : serverToTableID.get(entry.getKey())) {
logs.put(state.getSecond().toString(), Table.ID.of(tableId));
}
}
}
return logs;
}
}
use of org.apache.accumulo.server.log.WalStateManager in project accumulo by apache.
the class ReplicationIT method correctRecordsCompleteFile.
@Test
public void correctRecordsCompleteFile() throws Exception {
Connector conn = getConnector();
String table = "table1";
conn.tableOperations().create(table);
// If we have more than one tserver, this is subject to a race condition.
conn.tableOperations().setProperty(table, Property.TABLE_REPLICATION.getKey(), "true");
BatchWriter bw = conn.createBatchWriter(table, new BatchWriterConfig());
for (int i = 0; i < 10; i++) {
Mutation m = new Mutation(Integer.toString(i));
m.put(new byte[0], new byte[0], new byte[0]);
bw.addMutation(m);
}
bw.close();
// After writing data, we'll get a replication table online
while (!ReplicationTable.isOnline(conn)) {
sleepUninterruptibly(MILLIS_BETWEEN_REPLICATION_TABLE_ONLINE_CHECKS, TimeUnit.MILLISECONDS);
}
Assert.assertTrue("Replication table did not exist", ReplicationTable.isOnline(conn));
for (int i = 0; i < 5; i++) {
if (conn.securityOperations().hasTablePermission("root", ReplicationTable.NAME, TablePermission.READ)) {
break;
}
log.info("Could not read replication table, waiting and will retry");
Thread.sleep(2000);
}
Assert.assertTrue("'root' user could not read the replication table", conn.securityOperations().hasTablePermission("root", ReplicationTable.NAME, TablePermission.READ));
Set<String> replRows = new HashSet<>();
int attempts = 5;
while (replRows.isEmpty() && attempts > 0) {
try (Scanner scanner = ReplicationTable.getScanner(conn)) {
StatusSection.limit(scanner);
for (Entry<Key, Value> entry : scanner) {
Key k = entry.getKey();
String fileUri = k.getRow().toString();
try {
new URI(fileUri);
} catch (URISyntaxException e) {
Assert.fail("Expected a valid URI: " + fileUri);
}
replRows.add(fileUri);
}
}
}
Set<String> wals = new HashSet<>();
attempts = 5;
Instance i = conn.getInstance();
ZooReaderWriter zk = new ZooReaderWriter(i.getZooKeepers(), i.getZooKeepersSessionTimeOut(), "");
while (wals.isEmpty() && attempts > 0) {
WalStateManager markers = new WalStateManager(i, zk);
for (Entry<Path, WalState> entry : markers.getAllState().entrySet()) {
wals.add(entry.getKey().toString());
}
attempts--;
}
// We only have one file that should need replication (no trace table)
// We should find an entry in tablet and in the repl row
Assert.assertEquals("Rows found: " + replRows, 1, replRows.size());
// There should only be one extra WALog that replication doesn't know about
replRows.removeAll(wals);
Assert.assertEquals(2, wals.size());
Assert.assertEquals(0, replRows.size());
}
use of org.apache.accumulo.server.log.WalStateManager in project accumulo by apache.
the class CloseWriteAheadLogReferences method getClosedLogs.
/**
* Construct the set of referenced WALs from zookeeper
*
* @param conn
* Connector
* @return The Set of WALs that are referenced in the metadata table
*/
protected HashSet<String> getClosedLogs(Connector conn) {
WalStateManager wals = new WalStateManager(conn.getInstance(), ZooReaderWriter.getInstance());
HashSet<String> result = new HashSet<>();
try {
for (Entry<Path, WalState> entry : wals.getAllState().entrySet()) {
if (entry.getValue() == WalState.UNREFERENCED || entry.getValue() == WalState.CLOSED) {
Path path = entry.getKey();
log.debug("Found closed WAL " + path.toString());
result.add(path.toString());
}
}
} catch (WalMarkerException e) {
throw new RuntimeException(e);
}
return result;
}
Aggregations