Search in sources :

Example 1 with WalState

use of org.apache.accumulo.server.log.WalStateManager.WalState 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);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Connector(org.apache.accumulo.core.client.Connector) Scanner(org.apache.accumulo.core.client.Scanner) MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) RootTable(org.apache.accumulo.core.metadata.RootTable) Table(org.apache.accumulo.core.client.impl.Table) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) Instance(org.apache.accumulo.core.client.Instance) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance) ArrayList(java.util.ArrayList) ZooReaderWriter(org.apache.accumulo.server.zookeeper.ZooReaderWriter) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) Entry(java.util.Map.Entry) WalStateManager(org.apache.accumulo.server.log.WalStateManager) WalState(org.apache.accumulo.server.log.WalStateManager.WalState) WalMarkerException(org.apache.accumulo.server.log.WalStateManager.WalMarkerException)

Example 2 with WalState

use of org.apache.accumulo.server.log.WalStateManager.WalState 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;
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Scanner(org.apache.accumulo.core.client.Scanner) Instance(org.apache.accumulo.core.client.Instance) TServerInstance(org.apache.accumulo.server.master.state.TServerInstance) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance) ZooReaderWriter(org.apache.accumulo.server.zookeeper.ZooReaderWriter) TServerInstance(org.apache.accumulo.server.master.state.TServerInstance) WalStateManager(org.apache.accumulo.server.log.WalStateManager) Value(org.apache.accumulo.core.data.Value) List(java.util.List) ArrayList(java.util.ArrayList) WalState(org.apache.accumulo.server.log.WalStateManager.WalState) UUID(java.util.UUID) UUID(java.util.UUID) Key(org.apache.accumulo.core.data.Key)

Example 3 with WalState

use of org.apache.accumulo.server.log.WalStateManager.WalState 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());
}
Also used : Path(org.apache.hadoop.fs.Path) Connector(org.apache.accumulo.core.client.Connector) Scanner(org.apache.accumulo.core.client.Scanner) Instance(org.apache.accumulo.core.client.Instance) TServerInstance(org.apache.accumulo.server.master.state.TServerInstance) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance) ZooReaderWriter(org.apache.accumulo.server.zookeeper.ZooReaderWriter) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) WalStateManager(org.apache.accumulo.server.log.WalStateManager) Value(org.apache.accumulo.core.data.Value) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) WalState(org.apache.accumulo.server.log.WalStateManager.WalState) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Key(org.apache.accumulo.core.data.Key) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with WalState

use of org.apache.accumulo.server.log.WalStateManager.WalState in project accumulo by apache.

the class GarbageCollectWriteAheadLogs method removeFiles.

private long removeFiles(Collection<Pair<WalState, Path>> collection, final GCStatus status) {
    for (Pair<WalState, Path> stateFile : collection) {
        Path path = stateFile.getSecond();
        log.debug("Removing {} WAL {}", stateFile.getFirst(), path);
        try {
            if (!useTrash || !fs.moveToTrash(path)) {
                fs.deleteRecursively(path);
            }
            status.currentLog.deleted++;
        } catch (FileNotFoundException ex) {
        // ignored
        } catch (IOException ex) {
            log.error("Unable to delete wal {}", path, ex);
        }
    }
    return status.currentLog.deleted;
}
Also used : Path(org.apache.hadoop.fs.Path) FileNotFoundException(java.io.FileNotFoundException) WalState(org.apache.accumulo.server.log.WalStateManager.WalState) IOException(java.io.IOException)

Example 5 with WalState

use of org.apache.accumulo.server.log.WalStateManager.WalState 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;
}
Also used : Path(org.apache.hadoop.fs.Path) WalStateManager(org.apache.accumulo.server.log.WalStateManager) WalState(org.apache.accumulo.server.log.WalStateManager.WalState) HashSet(java.util.HashSet) WalMarkerException(org.apache.accumulo.server.log.WalStateManager.WalMarkerException)

Aggregations

WalState (org.apache.accumulo.server.log.WalStateManager.WalState)8 Path (org.apache.hadoop.fs.Path)8 WalStateManager (org.apache.accumulo.server.log.WalStateManager)6 Instance (org.apache.accumulo.core.client.Instance)5 ZooReaderWriter (org.apache.accumulo.server.zookeeper.ZooReaderWriter)5 HashSet (java.util.HashSet)4 Connector (org.apache.accumulo.core.client.Connector)3 Scanner (org.apache.accumulo.core.client.Scanner)3 ZooKeeperInstance (org.apache.accumulo.core.client.ZooKeeperInstance)3 TServerInstance (org.apache.accumulo.server.master.state.TServerInstance)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 UUID (java.util.UUID)2 Key (org.apache.accumulo.core.data.Key)2 Value (org.apache.accumulo.core.data.Value)2 WalMarkerException (org.apache.accumulo.server.log.WalStateManager.WalMarkerException)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1