Search in sources :

Example 11 with ProcessReference

use of org.apache.accumulo.miniclusterImpl.ProcessReference in project accumulo by apache.

the class UnorderedWorkAssignerReplicationIT method dataReplicatedToCorrectTable.

@Test
public void dataReplicatedToCorrectTable() throws Exception {
    MiniAccumuloConfigImpl peerCfg = new MiniAccumuloConfigImpl(createTestDir(this.getClass().getName() + "_" + this.testName.getMethodName() + "_peer"), ROOT_PASSWORD);
    peerCfg.setNumTservers(1);
    peerCfg.setInstanceName("peer");
    updatePeerConfigFromPrimary(getCluster().getConfig(), peerCfg);
    peerCfg.setProperty(Property.REPLICATION_NAME, "peer");
    MiniAccumuloClusterImpl peer1Cluster = new MiniAccumuloClusterImpl(peerCfg);
    peer1Cluster.start();
    try (AccumuloClient clientManager = Accumulo.newClient().from(getClientProperties()).build();
        AccumuloClient clientPeer = peer1Cluster.createAccumuloClient("root", new PasswordToken(ROOT_PASSWORD))) {
        String peerClusterName = "peer";
        String peerUserName = "peer", peerPassword = "foo";
        // Create local user
        clientPeer.securityOperations().createLocalUser(peerUserName, new PasswordToken(peerPassword));
        clientManager.instanceOperations().setProperty(Property.REPLICATION_PEER_USER.getKey() + peerClusterName, peerUserName);
        clientManager.instanceOperations().setProperty(Property.REPLICATION_PEER_PASSWORD.getKey() + peerClusterName, peerPassword);
        // ...peer = AccumuloReplicaSystem,instanceName,zookeepers
        clientManager.instanceOperations().setProperty(Property.REPLICATION_PEERS.getKey() + peerClusterName, ReplicaSystemFactory.getPeerConfigurationValue(AccumuloReplicaSystem.class, AccumuloReplicaSystem.buildConfiguration(peer1Cluster.getInstanceName(), peer1Cluster.getZooKeepers())));
        String managerTable1 = "manager1", peerTable1 = "peer1", managerTable2 = "manager2", peerTable2 = "peer2";
        // Create tables
        clientPeer.tableOperations().create(peerTable1);
        String peerTableId1 = clientPeer.tableOperations().tableIdMap().get(peerTable1);
        assertNotNull(peerTableId1);
        clientPeer.tableOperations().create(peerTable2);
        String peerTableId2 = clientPeer.tableOperations().tableIdMap().get(peerTable2);
        assertNotNull(peerTableId2);
        // Grant write permission
        clientPeer.securityOperations().grantTablePermission(peerUserName, peerTable1, TablePermission.WRITE);
        clientPeer.securityOperations().grantTablePermission(peerUserName, peerTable2, TablePermission.WRITE);
        Map<String, String> props1 = new HashMap<>();
        props1.put(Property.TABLE_REPLICATION.getKey(), "true");
        props1.put(Property.TABLE_REPLICATION_TARGET.getKey() + peerClusterName, peerTableId1);
        clientManager.tableOperations().create(managerTable1, new NewTableConfiguration().setProperties(props1));
        String managerTableId1 = clientManager.tableOperations().tableIdMap().get(managerTable1);
        assertNotNull(managerTableId1);
        Map<String, String> props2 = new HashMap<>();
        props2.put(Property.TABLE_REPLICATION.getKey(), "true");
        props2.put(Property.TABLE_REPLICATION_TARGET.getKey() + peerClusterName, peerTableId2);
        clientManager.tableOperations().create(managerTable2, new NewTableConfiguration().setProperties(props2));
        String managerTableId2 = clientManager.tableOperations().tableIdMap().get(managerTable2);
        assertNotNull(managerTableId2);
        // Wait for zookeeper updates (configuration) to propagate
        sleepUninterruptibly(3, TimeUnit.SECONDS);
        // Write some data to table1
        long managerTable1Records = 0L;
        try (BatchWriter bw = clientManager.createBatchWriter(managerTable1)) {
            for (int rows = 0; rows < 2500; rows++) {
                Mutation m = new Mutation(managerTable1 + rows);
                for (int cols = 0; cols < 100; cols++) {
                    String value = Integer.toString(cols);
                    m.put(value, "", value);
                    managerTable1Records++;
                }
                bw.addMutation(m);
            }
        }
        // Write some data to table2
        long managerTable2Records = 0L;
        try (BatchWriter bw = clientManager.createBatchWriter(managerTable2)) {
            for (int rows = 0; rows < 2500; rows++) {
                Mutation m = new Mutation(managerTable2 + rows);
                for (int cols = 0; cols < 100; cols++) {
                    String value = Integer.toString(cols);
                    m.put(value, "", value);
                    managerTable2Records++;
                }
                bw.addMutation(m);
            }
        }
        log.info("Wrote all data to manager cluster");
        Set<String> filesFor1 = clientManager.replicationOperations().referencedFiles(managerTable1), filesFor2 = clientManager.replicationOperations().referencedFiles(managerTable2);
        while (!ReplicationTable.isOnline(clientManager)) {
            Thread.sleep(500);
        }
        // Restart the tserver to force a close on the WAL
        for (ProcessReference proc : cluster.getProcesses().get(ServerType.TABLET_SERVER)) {
            cluster.killProcess(ServerType.TABLET_SERVER, proc);
        }
        cluster.exec(TabletServer.class);
        log.info("Restarted the tserver");
        // Read the data -- the tserver is back up and running
        Iterators.size(clientManager.createScanner(managerTable1, Authorizations.EMPTY).iterator());
        // Wait for both tables to be replicated
        log.info("Waiting for {} for {}", filesFor1, managerTable1);
        clientManager.replicationOperations().drain(managerTable1, filesFor1);
        log.info("Waiting for {} for {}", filesFor2, managerTable2);
        clientManager.replicationOperations().drain(managerTable2, filesFor2);
        long countTable = 0L;
        for (int i = 0; i < 5; i++) {
            countTable = 0L;
            for (Entry<Key, Value> entry : clientPeer.createScanner(peerTable1, Authorizations.EMPTY)) {
                countTable++;
                assertTrue("Found unexpected key-value" + entry.getKey().toStringNoTruncate() + " " + entry.getValue(), entry.getKey().getRow().toString().startsWith(managerTable1));
            }
            log.info("Found {} records in {}", countTable, peerTable1);
            if (managerTable1Records != countTable) {
                log.warn("Did not find {} expected records in {}, only found {}", managerTable1Records, peerTable1, countTable);
            }
        }
        assertEquals(managerTable1Records, countTable);
        for (int i = 0; i < 5; i++) {
            countTable = 0L;
            for (Entry<Key, Value> entry : clientPeer.createScanner(peerTable2, Authorizations.EMPTY)) {
                countTable++;
                assertTrue("Found unexpected key-value" + entry.getKey().toStringNoTruncate() + " " + entry.getValue(), entry.getKey().getRow().toString().startsWith(managerTable2));
            }
            log.info("Found {} records in {}", countTable, peerTable2);
            if (managerTable2Records != countTable) {
                log.warn("Did not find {} expected records in {}, only found {}", managerTable2Records, peerTable2, countTable);
            }
        }
        assertEquals(managerTable2Records, countTable);
    } finally {
        peer1Cluster.stop();
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) ProcessReference(org.apache.accumulo.miniclusterImpl.ProcessReference) HashMap(java.util.HashMap) MiniAccumuloConfigImpl(org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) Value(org.apache.accumulo.core.data.Value) AccumuloReplicaSystem(org.apache.accumulo.tserver.replication.AccumuloReplicaSystem) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) MiniAccumuloClusterImpl(org.apache.accumulo.miniclusterImpl.MiniAccumuloClusterImpl) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey) Test(org.junit.Test)

Example 12 with ProcessReference

use of org.apache.accumulo.miniclusterImpl.ProcessReference in project accumulo by apache.

the class UnorderedWorkAssignerReplicationIT method dataWasReplicatedToThePeerWithoutDrain.

@Test
public void dataWasReplicatedToThePeerWithoutDrain() throws Exception {
    MiniAccumuloConfigImpl peerCfg = new MiniAccumuloConfigImpl(createTestDir(this.getClass().getName() + "_" + this.testName.getMethodName() + "_peer"), ROOT_PASSWORD);
    peerCfg.setNumTservers(1);
    peerCfg.setInstanceName("peer");
    updatePeerConfigFromPrimary(getCluster().getConfig(), peerCfg);
    peerCfg.setProperty(Property.REPLICATION_NAME, "peer");
    MiniAccumuloClusterImpl peerCluster = new MiniAccumuloClusterImpl(peerCfg);
    peerCluster.start();
    try (AccumuloClient clientManager = Accumulo.newClient().from(getClientProperties()).build();
        AccumuloClient clientPeer = peerCluster.createAccumuloClient("root", new PasswordToken(ROOT_PASSWORD))) {
        String peerUserName = "repl";
        String peerPassword = "passwd";
        // Create a user on the peer for replication to use
        clientPeer.securityOperations().createLocalUser(peerUserName, new PasswordToken(peerPassword));
        String peerClusterName = "peer";
        // ...peer = AccumuloReplicaSystem,instanceName,zookeepers
        clientManager.instanceOperations().setProperty(Property.REPLICATION_PEERS.getKey() + peerClusterName, ReplicaSystemFactory.getPeerConfigurationValue(AccumuloReplicaSystem.class, AccumuloReplicaSystem.buildConfiguration(peerCluster.getInstanceName(), peerCluster.getZooKeepers())));
        // Configure the credentials we should use to authenticate ourselves to the peer for
        // replication
        clientManager.instanceOperations().setProperty(Property.REPLICATION_PEER_USER.getKey() + peerClusterName, peerUserName);
        clientManager.instanceOperations().setProperty(Property.REPLICATION_PEER_PASSWORD.getKey() + peerClusterName, peerPassword);
        String managerTable = "manager", peerTable = "peer";
        clientPeer.tableOperations().create(peerTable);
        String peerTableId = clientPeer.tableOperations().tableIdMap().get(peerTable);
        assertNotNull(peerTableId);
        Map<String, String> props = new HashMap<>();
        props.put(Property.TABLE_REPLICATION.getKey(), "true");
        props.put(Property.TABLE_REPLICATION_TARGET.getKey() + peerClusterName, peerTableId);
        clientManager.tableOperations().create(managerTable, new NewTableConfiguration().setProperties(props));
        String managerTableId = clientManager.tableOperations().tableIdMap().get(managerTable);
        assertNotNull(managerTableId);
        // Give our replication user the ability to write to the table
        clientPeer.securityOperations().grantTablePermission(peerUserName, peerTable, TablePermission.WRITE);
        // Write some data to table1
        try (BatchWriter bw = clientManager.createBatchWriter(managerTable)) {
            for (int rows = 0; rows < 5000; rows++) {
                Mutation m = new Mutation(Integer.toString(rows));
                for (int cols = 0; cols < 100; cols++) {
                    String value = Integer.toString(cols);
                    m.put(value, "", value);
                }
                bw.addMutation(m);
            }
        }
        log.info("Wrote all data to manager cluster");
        Set<String> files = clientManager.replicationOperations().referencedFiles(managerTable);
        for (String s : files) {
            log.info("Found referenced file for {}: {}", managerTable, s);
        }
        for (ProcessReference proc : cluster.getProcesses().get(ServerType.TABLET_SERVER)) {
            cluster.killProcess(ServerType.TABLET_SERVER, proc);
        }
        cluster.exec(TabletServer.class);
        Iterators.size(clientManager.createScanner(managerTable, Authorizations.EMPTY).iterator());
        try (var scanner = clientManager.createScanner(ReplicationTable.NAME, Authorizations.EMPTY)) {
            for (Entry<Key, Value> kv : scanner) {
                log.debug("{} {}", kv.getKey().toStringNoTruncate(), ProtobufUtil.toString(Status.parseFrom(kv.getValue().get())));
            }
        }
        clientManager.replicationOperations().drain(managerTable, files);
        try (Scanner manager = clientManager.createScanner(managerTable, Authorizations.EMPTY);
            Scanner peer = clientPeer.createScanner(peerTable, Authorizations.EMPTY)) {
            Iterator<Entry<Key, Value>> managerIter = manager.iterator(), peerIter = peer.iterator();
            assertTrue("No data in manager table", managerIter.hasNext());
            assertTrue("No data in peer table", peerIter.hasNext());
            while (managerIter.hasNext() && peerIter.hasNext()) {
                Entry<Key, Value> managerEntry = managerIter.next(), peerEntry = peerIter.next();
                assertEquals(peerEntry.getKey() + " was not equal to " + peerEntry.getKey(), 0, managerEntry.getKey().compareTo(peerEntry.getKey(), PartialKey.ROW_COLFAM_COLQUAL_COLVIS));
                assertEquals(managerEntry.getValue(), peerEntry.getValue());
            }
            assertFalse("Had more data to read from the manager", managerIter.hasNext());
            assertFalse("Had more data to read from the peer", peerIter.hasNext());
        }
        peerCluster.stop();
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) Scanner(org.apache.accumulo.core.client.Scanner) ProcessReference(org.apache.accumulo.miniclusterImpl.ProcessReference) HashMap(java.util.HashMap) MiniAccumuloConfigImpl(org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) Entry(java.util.Map.Entry) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) Value(org.apache.accumulo.core.data.Value) AccumuloReplicaSystem(org.apache.accumulo.tserver.replication.AccumuloReplicaSystem) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) MiniAccumuloClusterImpl(org.apache.accumulo.miniclusterImpl.MiniAccumuloClusterImpl) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey) Test(org.junit.Test)

Example 13 with ProcessReference

use of org.apache.accumulo.miniclusterImpl.ProcessReference in project accumulo by apache.

the class ThriftServerBindsBeforeZooKeeperLockIT method testMonitorService.

@SuppressFBWarnings(value = "URLCONNECTION_SSRF_FD", justification = "url is not from user")
@Test
public void testMonitorService() throws Exception {
    final MiniAccumuloClusterImpl cluster = (MiniAccumuloClusterImpl) getCluster();
    Collection<ProcessReference> monitors = cluster.getProcesses().get(ServerType.MONITOR);
    // Need to start one monitor and let it become active.
    if (monitors == null || monitors.isEmpty()) {
        getClusterControl().start(ServerType.MONITOR, "localhost");
    }
    while (true) {
        try {
            MonitorUtil.getLocation(getServerContext());
            break;
        } catch (Exception e) {
            LOG.debug("Failed to find active monitor location, retrying", e);
            Thread.sleep(1000);
        }
    }
    LOG.debug("Found active monitor");
    int freePort = PortUtils.getRandomFreePort();
    String monitorUrl = "http://localhost:" + freePort;
    Process monitor = null;
    try {
        LOG.debug("Starting standby monitor on {}", freePort);
        monitor = startProcess(cluster, ServerType.MONITOR, freePort);
        while (true) {
            URL url = new URL(monitorUrl);
            try {
                HttpURLConnection cnxn = (HttpURLConnection) url.openConnection();
                final int responseCode = cnxn.getResponseCode();
                String errorText;
                // This is our "assertion", but we want to re-check it if it's not what we expect
                if (responseCode == HttpURLConnection.HTTP_OK) {
                    return;
                } else {
                    errorText = FunctionalTestUtils.readAll(cnxn.getErrorStream());
                }
                LOG.debug("Unexpected responseCode and/or error text, will retry: '{}' '{}'", responseCode, errorText);
            } catch (Exception e) {
                LOG.debug("Caught exception trying to fetch monitor info", e);
            }
            // Wait before trying again
            Thread.sleep(1000);
            // died trying to bind it. Pick a new port and restart it in that case.
            if (!monitor.isAlive()) {
                freePort = PortUtils.getRandomFreePort();
                monitorUrl = "http://localhost:" + freePort;
                LOG.debug("Monitor died, restarting it listening on {}", freePort);
                monitor = startProcess(cluster, ServerType.MONITOR, freePort);
            }
        }
    } finally {
        if (monitor != null) {
            monitor.destroyForcibly();
        }
    }
}
Also used : ProcessReference(org.apache.accumulo.miniclusterImpl.ProcessReference) HttpURLConnection(java.net.HttpURLConnection) MiniAccumuloClusterImpl(org.apache.accumulo.miniclusterImpl.MiniAccumuloClusterImpl) IOException(java.io.IOException) URL(java.net.URL) Test(org.junit.Test) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 14 with ProcessReference

use of org.apache.accumulo.miniclusterImpl.ProcessReference in project accumulo by apache.

the class KerberosReplicationIT method dataReplicatedToCorrectTable.

@Test
public void dataReplicatedToCorrectTable() throws Exception {
    // Login as the root user
    final UserGroupInformation ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(rootUser.getPrincipal(), rootUser.getKeytab().toURI().toString());
    ugi.doAs((PrivilegedExceptionAction<Void>) () -> {
        log.info("testing {}", ugi);
        final KerberosToken token = new KerberosToken();
        try (AccumuloClient primaryclient = primary.createAccumuloClient(rootUser.getPrincipal(), token);
            AccumuloClient peerclient = peer.createAccumuloClient(rootUser.getPrincipal(), token)) {
            ClusterUser replicationUser = kdc.getClientPrincipal(0);
            // Create user for replication to the peer
            peerclient.securityOperations().createLocalUser(replicationUser.getPrincipal(), null);
            primaryclient.instanceOperations().setProperty(Property.REPLICATION_PEER_USER.getKey() + PEER_NAME, replicationUser.getPrincipal());
            primaryclient.instanceOperations().setProperty(Property.REPLICATION_PEER_KEYTAB.getKey() + PEER_NAME, replicationUser.getKeytab().getAbsolutePath());
            // ...peer = AccumuloReplicaSystem,instanceName,zookeepers
            ClientInfo info = ClientInfo.from(peerclient.properties());
            primaryclient.instanceOperations().setProperty(Property.REPLICATION_PEERS.getKey() + PEER_NAME, ReplicaSystemFactory.getPeerConfigurationValue(AccumuloReplicaSystem.class, AccumuloReplicaSystem.buildConfiguration(info.getInstanceName(), info.getZooKeepers())));
            String primaryTable1 = "primary", peerTable1 = "peer";
            // Create tables
            peerclient.tableOperations().create(peerTable1);
            String peerTableId1 = peerclient.tableOperations().tableIdMap().get(peerTable1);
            assertNotNull(peerTableId1);
            Map<String, String> props = new HashMap<>();
            props.put(Property.TABLE_REPLICATION.getKey(), "true");
            // Replicate this table to the peerClusterName in a table with the peerTableId table id
            props.put(Property.TABLE_REPLICATION_TARGET.getKey() + PEER_NAME, peerTableId1);
            primaryclient.tableOperations().create(primaryTable1, new NewTableConfiguration().setProperties(props));
            String managerTableId1 = primaryclient.tableOperations().tableIdMap().get(primaryTable1);
            assertNotNull(managerTableId1);
            // Grant write permission
            peerclient.securityOperations().grantTablePermission(replicationUser.getPrincipal(), peerTable1, TablePermission.WRITE);
            // Write some data to table1
            long managerTable1Records = 0L;
            try (BatchWriter bw = primaryclient.createBatchWriter(primaryTable1)) {
                for (int rows = 0; rows < 2500; rows++) {
                    Mutation m = new Mutation(primaryTable1 + rows);
                    for (int cols = 0; cols < 100; cols++) {
                        String value = Integer.toString(cols);
                        m.put(value, "", value);
                        managerTable1Records++;
                    }
                    bw.addMutation(m);
                }
            }
            log.info("Wrote all data to primary cluster");
            Set<String> filesFor1 = primaryclient.replicationOperations().referencedFiles(primaryTable1);
            // Restart the tserver to force a close on the WAL
            for (ProcessReference proc : primary.getProcesses().get(ServerType.TABLET_SERVER)) {
                primary.killProcess(ServerType.TABLET_SERVER, proc);
            }
            primary.exec(TabletServer.class);
            log.info("Restarted the tserver");
            // Read the data -- the tserver is back up and running and tablets are assigned
            Iterators.size(primaryclient.createScanner(primaryTable1, Authorizations.EMPTY).iterator());
            // Wait for both tables to be replicated
            log.info("Waiting for {} for {}", filesFor1, primaryTable1);
            primaryclient.replicationOperations().drain(primaryTable1, filesFor1);
            long countTable = 0L;
            try (var scanner = peerclient.createScanner(peerTable1, Authorizations.EMPTY)) {
                for (Entry<Key, Value> entry : scanner) {
                    countTable++;
                    assertTrue("Found unexpected key-value" + entry.getKey().toStringNoTruncate() + " " + entry.getValue(), entry.getKey().getRow().toString().startsWith(primaryTable1));
                }
            }
            log.info("Found {} records in {}", countTable, peerTable1);
            assertEquals(managerTable1Records, countTable);
            return null;
        }
    });
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) ProcessReference(org.apache.accumulo.miniclusterImpl.ProcessReference) Set(java.util.Set) KerberosToken(org.apache.accumulo.core.client.security.tokens.KerberosToken) Entry(java.util.Map.Entry) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) TabletServer(org.apache.accumulo.tserver.TabletServer) ClusterUser(org.apache.accumulo.cluster.ClusterUser) ClientInfo(org.apache.accumulo.core.clientImpl.ClientInfo) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Map(java.util.Map) HashMap(java.util.HashMap) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Test(org.junit.Test)

Example 15 with ProcessReference

use of org.apache.accumulo.miniclusterImpl.ProcessReference in project accumulo by apache.

the class MultiInstanceReplicationIT method dataReplicatedToCorrectTable.

@Test
public void dataReplicatedToCorrectTable() throws Exception {
    MiniAccumuloConfigImpl peerCfg = new MiniAccumuloConfigImpl(createTestDir(this.getClass().getName() + "_" + this.testName.getMethodName() + "_peer"), ROOT_PASSWORD);
    peerCfg.setNumTservers(1);
    peerCfg.setInstanceName("peer");
    peerCfg.setProperty(Property.REPLICATION_NAME, "peer");
    updatePeerConfigFromPrimary(getCluster().getConfig(), peerCfg);
    MiniAccumuloClusterImpl peer1Cluster = new MiniAccumuloClusterImpl(peerCfg);
    peer1Cluster.start();
    try (AccumuloClient clientManager = Accumulo.newClient().from(getClientProperties()).build();
        AccumuloClient clientPeer = peer1Cluster.createAccumuloClient("root", new PasswordToken(ROOT_PASSWORD))) {
        String peerClusterName = "peer";
        String peerUserName = "peer", peerPassword = "foo";
        // Create local user
        clientPeer.securityOperations().createLocalUser(peerUserName, new PasswordToken(peerPassword));
        clientManager.instanceOperations().setProperty(Property.REPLICATION_PEER_USER.getKey() + peerClusterName, peerUserName);
        clientManager.instanceOperations().setProperty(Property.REPLICATION_PEER_PASSWORD.getKey() + peerClusterName, peerPassword);
        // ...peer = AccumuloReplicaSystem,instanceName,zookeepers
        clientManager.instanceOperations().setProperty(Property.REPLICATION_PEERS.getKey() + peerClusterName, ReplicaSystemFactory.getPeerConfigurationValue(AccumuloReplicaSystem.class, AccumuloReplicaSystem.buildConfiguration(peer1Cluster.getInstanceName(), peer1Cluster.getZooKeepers())));
        String managerTable1 = "manager1", peerTable1 = "peer1", managerTable2 = "manager2", peerTable2 = "peer2";
        // Create tables
        clientPeer.tableOperations().create(peerTable1, new NewTableConfiguration());
        String peerTableId1 = clientPeer.tableOperations().tableIdMap().get(peerTable1);
        assertNotNull(peerTableId1);
        clientPeer.tableOperations().create(peerTable2, new NewTableConfiguration());
        String peerTableId2 = clientPeer.tableOperations().tableIdMap().get(peerTable2);
        assertNotNull(peerTableId2);
        Map<String, String> props1 = new HashMap<>();
        props1.put(Property.TABLE_REPLICATION.getKey(), "true");
        props1.put(Property.TABLE_REPLICATION_TARGET.getKey() + peerClusterName, peerTableId1);
        clientManager.tableOperations().create(managerTable1, new NewTableConfiguration().setProperties(props1));
        String managerTableId1 = clientManager.tableOperations().tableIdMap().get(managerTable1);
        assertNotNull(managerTableId1);
        Map<String, String> props2 = new HashMap<>();
        props2.put(Property.TABLE_REPLICATION.getKey(), "true");
        props2.put(Property.TABLE_REPLICATION_TARGET.getKey() + peerClusterName, peerTableId2);
        clientManager.tableOperations().create(managerTable2, new NewTableConfiguration().setProperties(props2));
        String managerTableId2 = clientManager.tableOperations().tableIdMap().get(managerTable2);
        assertNotNull(managerTableId2);
        // Give our replication user the ability to write to the tables
        clientPeer.securityOperations().grantTablePermission(peerUserName, peerTable1, TablePermission.WRITE);
        clientPeer.securityOperations().grantTablePermission(peerUserName, peerTable2, TablePermission.WRITE);
        // Write some data to table1
        long managerTable1Records = 0L;
        try (BatchWriter bw = clientManager.createBatchWriter(managerTable1)) {
            for (int rows = 0; rows < 2500; rows++) {
                Mutation m = new Mutation(managerTable1 + rows);
                for (int cols = 0; cols < 100; cols++) {
                    String value = Integer.toString(cols);
                    m.put(value, "", value);
                    managerTable1Records++;
                }
                bw.addMutation(m);
            }
        }
        // Write some data to table2
        long managerTable2Records = 0L;
        try (BatchWriter bw = clientManager.createBatchWriter(managerTable2)) {
            for (int rows = 0; rows < 2500; rows++) {
                Mutation m = new Mutation(managerTable2 + rows);
                for (int cols = 0; cols < 100; cols++) {
                    String value = Integer.toString(cols);
                    m.put(value, "", value);
                    managerTable2Records++;
                }
                bw.addMutation(m);
            }
        }
        log.info("Wrote all data to manager cluster");
        Set<String> filesFor1 = clientManager.replicationOperations().referencedFiles(managerTable1), filesFor2 = clientManager.replicationOperations().referencedFiles(managerTable2);
        log.info("Files to replicate for table1: " + filesFor1);
        log.info("Files to replicate for table2: " + filesFor2);
        // Restart the tserver to force a close on the WAL
        for (ProcessReference proc : cluster.getProcesses().get(ServerType.TABLET_SERVER)) {
            cluster.killProcess(ServerType.TABLET_SERVER, proc);
        }
        cluster.exec(TabletServer.class);
        log.info("Restarted the tserver");
        // Read the data -- the tserver is back up and running
        Iterators.size(clientManager.createScanner(managerTable1, Authorizations.EMPTY).iterator());
        while (!ReplicationTable.isOnline(clientManager)) {
            log.info("Replication table still offline, waiting");
            Thread.sleep(5000);
        }
        // Wait for both tables to be replicated
        log.info("Waiting for {} for {}", filesFor1, managerTable1);
        clientManager.replicationOperations().drain(managerTable1, filesFor1);
        log.info("Waiting for {} for {}", filesFor2, managerTable2);
        clientManager.replicationOperations().drain(managerTable2, filesFor2);
        long countTable = 0L;
        try (var scanner = clientPeer.createScanner(peerTable1, Authorizations.EMPTY)) {
            for (Entry<Key, Value> entry : scanner) {
                countTable++;
                assertTrue("Found unexpected key-value" + entry.getKey().toStringNoTruncate() + " " + entry.getValue(), entry.getKey().getRow().toString().startsWith(managerTable1));
            }
        }
        log.info("Found {} records in {}", countTable, peerTable1);
        assertEquals(managerTable1Records, countTable);
        countTable = 0L;
        try (var scanner = clientPeer.createScanner(peerTable2, Authorizations.EMPTY)) {
            for (Entry<Key, Value> entry : scanner) {
                countTable++;
                assertTrue("Found unexpected key-value" + entry.getKey().toStringNoTruncate() + " " + entry.getValue(), entry.getKey().getRow().toString().startsWith(managerTable2));
            }
        }
        log.info("Found {} records in {}", countTable, peerTable2);
        assertEquals(managerTable2Records, countTable);
    } finally {
        peer1Cluster.stop();
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) ProcessReference(org.apache.accumulo.miniclusterImpl.ProcessReference) HashMap(java.util.HashMap) MiniAccumuloConfigImpl(org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) Value(org.apache.accumulo.core.data.Value) AccumuloReplicaSystem(org.apache.accumulo.tserver.replication.AccumuloReplicaSystem) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) MiniAccumuloClusterImpl(org.apache.accumulo.miniclusterImpl.MiniAccumuloClusterImpl) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey) Test(org.junit.Test)

Aggregations

ProcessReference (org.apache.accumulo.miniclusterImpl.ProcessReference)20 Test (org.junit.Test)19 AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)18 BatchWriter (org.apache.accumulo.core.client.BatchWriter)13 Mutation (org.apache.accumulo.core.data.Mutation)13 NewTableConfiguration (org.apache.accumulo.core.client.admin.NewTableConfiguration)12 MiniAccumuloClusterImpl (org.apache.accumulo.miniclusterImpl.MiniAccumuloClusterImpl)12 MiniAccumuloConfigImpl (org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl)11 HashMap (java.util.HashMap)10 Scanner (org.apache.accumulo.core.client.Scanner)10 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)10 Key (org.apache.accumulo.core.data.Key)10 Value (org.apache.accumulo.core.data.Value)10 AccumuloReplicaSystem (org.apache.accumulo.tserver.replication.AccumuloReplicaSystem)9 PartialKey (org.apache.accumulo.core.data.PartialKey)8 Entry (java.util.Map.Entry)7 ArrayList (java.util.ArrayList)3 TreeSet (java.util.TreeSet)3 TimeoutException (java.util.concurrent.TimeoutException)3 Text (org.apache.hadoop.io.Text)3