Search in sources :

Example 26 with ServerContext

use of org.apache.accumulo.server.ServerContext in project accumulo by apache.

the class ReplicationProcessorTest method peerTypeExtractionFromConfiguration.

@Test
public void peerTypeExtractionFromConfiguration() {
    ServerContext context = createMock(ServerContext.class);
    String peerName = "peer";
    String configuration = "java.lang.String,foo";
    var conf = new ConfigurationCopy(Map.of(Property.REPLICATION_PEERS + peerName, configuration));
    expect(context.getConfiguration()).andReturn(conf);
    replay(context);
    ReplicationProcessor proc = new ReplicationProcessor(context);
    assertEquals(configuration, proc.getPeerType(peerName));
    verify(context);
}
Also used : ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) ServerContext(org.apache.accumulo.server.ServerContext) Test(org.junit.Test)

Example 27 with ServerContext

use of org.apache.accumulo.server.ServerContext in project accumulo by apache.

the class InMemoryMapTest method getServerContext.

public static ServerContext getServerContext() {
    Configuration hadoopConf = new Configuration();
    ServerContext context = EasyMock.createMock(ServerContext.class);
    EasyMock.expect(context.getCryptoService()).andReturn(CryptoServiceFactory.newDefaultInstance()).anyTimes();
    EasyMock.expect(context.getConfiguration()).andReturn(DefaultConfiguration.getInstance()).anyTimes();
    EasyMock.expect(context.getHadoopConf()).andReturn(hadoopConf).anyTimes();
    EasyMock.replay(context);
    return context;
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) SamplerConfiguration(org.apache.accumulo.core.client.sample.SamplerConfiguration) DefaultConfiguration(org.apache.accumulo.core.conf.DefaultConfiguration) ServerContext(org.apache.accumulo.server.ServerContext)

Example 28 with ServerContext

use of org.apache.accumulo.server.ServerContext in project accumulo by apache.

the class CloseWriteAheadLogReferencesIT method setupEasyMockStuff.

@Before
public void setupEasyMockStuff() {
    SiteConfiguration siteConfig = EasyMock.createMock(SiteConfiguration.class);
    final AccumuloConfiguration systemConf = new ConfigurationCopy(new HashMap<>());
    // Just make the SiteConfiguration delegate to our AccumuloConfiguration
    // Presently, we only need get(Property) and iterator().
    EasyMock.expect(siteConfig.get(EasyMock.anyObject(Property.class))).andAnswer(() -> {
        Object[] args = EasyMock.getCurrentArguments();
        return systemConf.get((Property) args[0]);
    }).anyTimes();
    EasyMock.expect(siteConfig.getBoolean(EasyMock.anyObject(Property.class))).andAnswer(() -> {
        Object[] args = EasyMock.getCurrentArguments();
        return systemConf.getBoolean((Property) args[0]);
    }).anyTimes();
    EasyMock.expect(siteConfig.iterator()).andAnswer(systemConf::iterator).anyTimes();
    ServerContext context = createMock(ServerContext.class);
    expect(context.getProperties()).andReturn(new Properties()).anyTimes();
    expect(context.getZooKeepers()).andReturn("localhost").anyTimes();
    expect(context.getInstanceName()).andReturn("test").anyTimes();
    expect(context.getZooKeepersSessionTimeOut()).andReturn(30000).anyTimes();
    expect(context.getInstanceID()).andReturn(InstanceId.of("1111")).anyTimes();
    expect(context.getZooKeeperRoot()).andReturn(Constants.ZROOT + "/1111").anyTimes();
    replay(siteConfig, context);
    refs = new WrappedCloseWriteAheadLogReferences(context);
}
Also used : ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) ServerContext(org.apache.accumulo.server.ServerContext) SiteConfiguration(org.apache.accumulo.core.conf.SiteConfiguration) Properties(java.util.Properties) Property(org.apache.accumulo.core.conf.Property) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) Before(org.junit.Before)

Example 29 with ServerContext

use of org.apache.accumulo.server.ServerContext in project accumulo by apache.

the class ZombieTServer method main.

public static void main(String[] args) throws Exception {
    int port = random.nextInt(30000) + 2000;
    var context = new ServerContext(SiteConfiguration.auto());
    TransactionWatcher watcher = new TransactionWatcher(context);
    final ThriftClientHandler tch = new ThriftClientHandler(context, watcher);
    Processor<Iface> processor = new Processor<>(tch);
    ServerAddress serverPort = TServerUtils.startTServer(context.getConfiguration(), ThriftServerType.CUSTOM_HS_HA, processor, "ZombieTServer", "walking dead", 2, ThreadPools.DEFAULT_TIMEOUT_MILLISECS, 1000, 10 * 1024 * 1024, null, null, -1, HostAndPort.fromParts("0.0.0.0", port));
    String addressString = serverPort.address.toString();
    var zLockPath = ServiceLock.path(context.getZooKeeperRoot() + Constants.ZTSERVERS + "/" + addressString);
    ZooReaderWriter zoo = context.getZooReaderWriter();
    zoo.putPersistentData(zLockPath.toString(), new byte[] {}, NodeExistsPolicy.SKIP);
    ServiceLock zlock = new ServiceLock(zoo.getZooKeeper(), zLockPath, UUID.randomUUID());
    LockWatcher lw = new LockWatcher() {

        @SuppressFBWarnings(value = "DM_EXIT", justification = "System.exit() is a bad idea here, but okay for now, since it's a test")
        @Override
        public void lostLock(final LockLossReason reason) {
            try {
                tch.halt(TraceUtil.traceInfo(), null, null);
            } catch (Exception ex) {
                log.error("Exception", ex);
                System.exit(1);
            }
        }

        @SuppressFBWarnings(value = "DM_EXIT", justification = "System.exit() is a bad idea here, but okay for now, since it's a test")
        @Override
        public void unableToMonitorLockNode(Exception e) {
            try {
                tch.halt(TraceUtil.traceInfo(), null, null);
            } catch (Exception ex) {
                log.error("Exception", ex);
                System.exit(1);
            }
        }
    };
    byte[] lockContent = new ServerServices(addressString, Service.TSERV_CLIENT).toString().getBytes(UTF_8);
    if (zlock.tryLock(lw, lockContent)) {
        log.debug("Obtained tablet server lock {}", zlock.getLockPath());
    }
    // modify metadata
    synchronized (tch) {
        while (!tch.halted) {
            tch.wait();
        }
    }
    System.exit(0);
}
Also used : Processor(org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Processor) ServerServices(org.apache.accumulo.core.util.ServerServices) ServerAddress(org.apache.accumulo.server.rpc.ServerAddress) ZooReaderWriter(org.apache.accumulo.fate.zookeeper.ZooReaderWriter) Iface(org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Iface) TransactionWatcher(org.apache.accumulo.server.zookeeper.TransactionWatcher) ServerContext(org.apache.accumulo.server.ServerContext) ServiceLock(org.apache.accumulo.fate.zookeeper.ServiceLock) LockWatcher(org.apache.accumulo.fate.zookeeper.ServiceLock.LockWatcher) LockLossReason(org.apache.accumulo.fate.zookeeper.ServiceLock.LockLossReason)

Example 30 with ServerContext

use of org.apache.accumulo.server.ServerContext in project accumulo by apache.

the class WALSunnyDayIT method test.

@Test
public void test() throws Exception {
    MiniAccumuloClusterImpl mac = getCluster();
    MiniAccumuloClusterControl control = mac.getClusterControl();
    control.stop(GARBAGE_COLLECTOR);
    ServerContext context = getServerContext();
    try (AccumuloClient c = Accumulo.newClient().from(getClientProperties()).build()) {
        String tableName = getUniqueNames(1)[0];
        c.tableOperations().create(tableName);
        writeSomeData(c, tableName, 1, 1);
        // wal markers are added lazily
        Map<String, WalState> wals = getWALsAndAssertCount(context, 2);
        assertEquals("all WALs should be in use", 2, countInUse(wals.values()));
        // roll log, get a new next
        writeSomeData(c, tableName, 1001, 50);
        Map<String, WalState> walsAfterRoll = getWALsAndAssertCount(context, 3);
        assertTrue("new WALs should be a superset of the old WALs", walsAfterRoll.keySet().containsAll(wals.keySet()));
        assertEquals("all WALs should be in use", 3, countInUse(walsAfterRoll.values()));
        // flush the tables
        for (String table : new String[] { tableName, MetadataTable.NAME, RootTable.NAME }) {
            c.tableOperations().flush(table, null, null, true);
        }
        sleepUninterruptibly(1, TimeUnit.SECONDS);
        // rolled WAL is no longer in use, but needs to be GC'd
        Map<String, WalState> walsAfterflush = getWALsAndAssertCount(context, 3);
        assertEquals("inUse should be 2", 2, countInUse(walsAfterflush.values()));
        // let the GC run for a little bit
        control.start(GARBAGE_COLLECTOR);
        sleepUninterruptibly(5, TimeUnit.SECONDS);
        // make sure the unused WAL goes away
        getWALsAndAssertCount(context, 2);
        control.stop(GARBAGE_COLLECTOR);
        // restart the tserver, but don't run recovery on all tablets
        control.stop(TABLET_SERVER);
        // this delays recovery on the normal tables
        assertEquals(0, cluster.exec(SetGoalState.class, "SAFE_MODE").getProcess().waitFor());
        control.start(TABLET_SERVER);
        // wait for the metadata table to go back online
        getRecoveryMarkers(c);
        // allow a little time for the manager to notice ASSIGNED_TO_DEAD_SERVER tablets
        sleepUninterruptibly(5, TimeUnit.SECONDS);
        Map<KeyExtent, List<String>> markers = getRecoveryMarkers(c);
        // log.debug("markers " + markers);
        assertEquals("one tablet should have markers", 1, markers.size());
        assertEquals("tableId of the keyExtent should be 1", "1", markers.keySet().iterator().next().tableId().canonical());
        // put some data in the WAL
        assertEquals(0, cluster.exec(SetGoalState.class, "NORMAL").getProcess().waitFor());
        verifySomeData(c, tableName, 1001 * 50 + 1);
        writeSomeData(c, tableName, 100, 100);
        Map<String, WalState> walsAfterRestart = getWALsAndAssertCount(context, 4);
        // log.debug("wals after " + walsAfterRestart);
        assertEquals("used WALs after restart should be 4", 4, countInUse(walsAfterRestart.values()));
        control.start(GARBAGE_COLLECTOR);
        sleepUninterruptibly(5, TimeUnit.SECONDS);
        Map<String, WalState> walsAfterRestartAndGC = getWALsAndAssertCount(context, 2);
        assertEquals("logs in use should be 2", 2, countInUse(walsAfterRestartAndGC.values()));
    }
}
Also used : MiniAccumuloClusterControl(org.apache.accumulo.miniclusterImpl.MiniAccumuloClusterControl) AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) ServerContext(org.apache.accumulo.server.ServerContext) WalState(org.apache.accumulo.server.log.WalStateManager.WalState) List(java.util.List) ArrayList(java.util.ArrayList) SetGoalState(org.apache.accumulo.manager.state.SetGoalState) MiniAccumuloClusterImpl(org.apache.accumulo.miniclusterImpl.MiniAccumuloClusterImpl) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) Test(org.junit.Test)

Aggregations

ServerContext (org.apache.accumulo.server.ServerContext)87 Test (org.junit.Test)41 ZooReaderWriter (org.apache.accumulo.fate.zookeeper.ZooReaderWriter)18 AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)15 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)15 TServerInstance (org.apache.accumulo.core.metadata.TServerInstance)15 HostAndPort (org.apache.accumulo.core.util.HostAndPort)15 Path (org.apache.hadoop.fs.Path)15 ArrayList (java.util.ArrayList)14 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)14 VolumeManager (org.apache.accumulo.server.fs.VolumeManager)13 KeeperException (org.apache.zookeeper.KeeperException)13 ServerAddress (org.apache.accumulo.server.rpc.ServerAddress)12 TableId (org.apache.accumulo.core.data.TableId)11 LiveTServerSet (org.apache.accumulo.server.manager.LiveTServerSet)11 Value (org.apache.accumulo.core.data.Value)10 IOException (java.io.IOException)9 UUID (java.util.UUID)9 ConfigurationCopy (org.apache.accumulo.core.conf.ConfigurationCopy)9 Client (org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Client)9