Search in sources :

Example 6 with AccumuloServerContext

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

the class HostRegexTableLoadBalancerTest method testPartiallyAssigned.

@Test
public void testPartiallyAssigned() {
    init(new AccumuloServerContext(instance, factory));
    Map<KeyExtent, TServerInstance> assignments = new HashMap<>();
    Map<KeyExtent, TServerInstance> unassigned = new HashMap<>();
    int i = 0;
    for (List<KeyExtent> extents : tableExtents.values()) {
        for (KeyExtent ke : extents) {
            if ((i % 2) == 0) {
                unassigned.put(ke, null);
            }
            i++;
        }
    }
    this.getAssignments(Collections.unmodifiableSortedMap(allTabletServers), Collections.unmodifiableMap(unassigned), assignments);
    Assert.assertEquals(unassigned.size(), assignments.size());
    // Ensure unique tservers
    for (Entry<KeyExtent, TServerInstance> e : assignments.entrySet()) {
        for (Entry<KeyExtent, TServerInstance> e2 : assignments.entrySet()) {
            if (e.getKey().equals(e2.getKey())) {
                continue;
            }
            if (e.getValue().equals(e2.getValue())) {
                Assert.fail("Assignment failure");
            }
        }
    }
    // Ensure assignments are correct
    for (Entry<KeyExtent, TServerInstance> e : assignments.entrySet()) {
        if (!tabletInBounds(e.getKey(), e.getValue())) {
            Assert.fail("tablet not in bounds: " + e.getKey() + " -> " + e.getValue().host());
        }
    }
}
Also used : AccumuloServerContext(org.apache.accumulo.server.AccumuloServerContext) HashMap(java.util.HashMap) TKeyExtent(org.apache.accumulo.core.data.thrift.TKeyExtent) KeyExtent(org.apache.accumulo.core.data.impl.KeyExtent) TServerInstance(org.apache.accumulo.server.master.state.TServerInstance) Test(org.junit.Test)

Example 7 with AccumuloServerContext

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

the class ZombieTServer method main.

public static void main(String[] args) throws Exception {
    Random random = new Random(System.currentTimeMillis() % 1000);
    int port = random.nextInt(30000) + 2000;
    Instance instance = HdfsZooInstance.getInstance();
    AccumuloServerContext context = new AccumuloServerContext(instance, new ServerConfigurationFactory(instance));
    TransactionWatcher watcher = new TransactionWatcher();
    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, 1, 1000, 10 * 1024 * 1024, null, null, -1, HostAndPort.fromParts("0.0.0.0", port));
    String addressString = serverPort.address.toString();
    String zPath = ZooUtil.getRoot(context.getInstance()) + Constants.ZTSERVERS + "/" + addressString;
    ZooReaderWriter zoo = ZooReaderWriter.getInstance();
    zoo.putPersistentData(zPath, new byte[] {}, NodeExistsPolicy.SKIP);
    ZooLock zlock = new ZooLock(zPath);
    LockWatcher lw = new LockWatcher() {

        @Override
        public void lostLock(final LockLossReason reason) {
            try {
                tch.halt(Tracer.traceInfo(), null, null);
            } catch (Exception ex) {
                log.error("Exception", ex);
                System.exit(1);
            }
        }

        @Override
        public void unableToMonitorLockNode(Throwable e) {
            try {
                tch.halt(Tracer.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 : AccumuloServerContext(org.apache.accumulo.server.AccumuloServerContext) Processor(org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Processor) ServerServices(org.apache.accumulo.core.util.ServerServices) Instance(org.apache.accumulo.core.client.Instance) HdfsZooInstance(org.apache.accumulo.server.client.HdfsZooInstance) ServerAddress(org.apache.accumulo.server.rpc.ServerAddress) ZooReaderWriter(org.apache.accumulo.server.zookeeper.ZooReaderWriter) ServerConfigurationFactory(org.apache.accumulo.server.conf.ServerConfigurationFactory) TException(org.apache.thrift.TException) ThriftSecurityException(org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException) Iface(org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Iface) TransactionWatcher(org.apache.accumulo.server.zookeeper.TransactionWatcher) Random(java.util.Random) LockWatcher(org.apache.accumulo.fate.zookeeper.ZooLock.LockWatcher) LockLossReason(org.apache.accumulo.fate.zookeeper.ZooLock.LockLossReason) ZooLock(org.apache.accumulo.server.zookeeper.ZooLock)

Example 8 with AccumuloServerContext

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

the class CloseWriteAheadLogReferencesIT method setupEasyMockStuff.

@Before
public void setupEasyMockStuff() {
    Instance mockInst = createMock(Instance.class);
    SiteConfiguration siteConfig = EasyMock.createMock(SiteConfiguration.class);
    expect(mockInst.getInstanceID()).andReturn(testName.getMethodName()).anyTimes();
    expect(mockInst.getZooKeepers()).andReturn("localhost").anyTimes();
    expect(mockInst.getZooKeepersSessionTimeOut()).andReturn(30000).anyTimes();
    final AccumuloConfiguration systemConf = new ConfigurationCopy(new HashMap<>());
    ServerConfigurationFactory factory = createMock(ServerConfigurationFactory.class);
    expect(factory.getSystemConfiguration()).andReturn(systemConf).anyTimes();
    expect(factory.getSiteConfiguration()).andReturn(siteConfig).anyTimes();
    // 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(new IAnswer<String>() {

        @Override
        public String answer() {
            Object[] args = EasyMock.getCurrentArguments();
            return systemConf.get((Property) args[0]);
        }
    }).anyTimes();
    EasyMock.expect(siteConfig.getBoolean(EasyMock.anyObject(Property.class))).andAnswer(new IAnswer<Boolean>() {

        @Override
        public Boolean answer() {
            Object[] args = EasyMock.getCurrentArguments();
            return systemConf.getBoolean((Property) args[0]);
        }
    }).anyTimes();
    EasyMock.expect(siteConfig.iterator()).andAnswer(new IAnswer<Iterator<Entry<String, String>>>() {

        @Override
        public Iterator<Entry<String, String>> answer() {
            return systemConf.iterator();
        }
    }).anyTimes();
    replay(mockInst, factory, siteConfig);
    refs = new WrappedCloseWriteAheadLogReferences(new AccumuloServerContext(mockInst, factory));
}
Also used : IAnswer(org.easymock.IAnswer) Entry(java.util.Map.Entry) ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) AccumuloServerContext(org.apache.accumulo.server.AccumuloServerContext) Instance(org.apache.accumulo.core.client.Instance) SiteConfiguration(org.apache.accumulo.core.conf.SiteConfiguration) ServerConfigurationFactory(org.apache.accumulo.server.conf.ServerConfigurationFactory) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) Before(org.junit.Before)

Example 9 with AccumuloServerContext

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

the class SplitRecoveryIT method run.

private void run() throws Exception {
    Instance inst = HdfsZooInstance.getInstance();
    AccumuloServerContext c = new AccumuloServerContext(inst, new ServerConfigurationFactory(inst));
    String zPath = ZooUtil.getRoot(inst) + "/testLock";
    IZooReaderWriter zoo = ZooReaderWriter.getInstance();
    zoo.putPersistentData(zPath, new byte[0], NodeExistsPolicy.OVERWRITE);
    ZooLock zl = new ZooLock(zPath);
    boolean gotLock = zl.tryLock(new LockWatcher() {

        @Override
        public void lostLock(LockLossReason reason) {
            System.exit(-1);
        }

        @Override
        public void unableToMonitorLockNode(Throwable e) {
            System.exit(-1);
        }
    }, "foo".getBytes(UTF_8));
    if (!gotLock) {
        System.err.println("Failed to get lock " + zPath);
    }
    // run test for a table with one tablet
    runSplitRecoveryTest(c, 0, "sp", 0, zl, nke("foo0", null, null));
    runSplitRecoveryTest(c, 1, "sp", 0, zl, nke("foo1", null, null));
    // run test for tables with two tablets, run test on first and last tablet
    runSplitRecoveryTest(c, 0, "k", 0, zl, nke("foo2", "m", null), nke("foo2", null, "m"));
    runSplitRecoveryTest(c, 1, "k", 0, zl, nke("foo3", "m", null), nke("foo3", null, "m"));
    runSplitRecoveryTest(c, 0, "o", 1, zl, nke("foo4", "m", null), nke("foo4", null, "m"));
    runSplitRecoveryTest(c, 1, "o", 1, zl, nke("foo5", "m", null), nke("foo5", null, "m"));
    // run test for table w/ three tablets, run test on middle tablet
    runSplitRecoveryTest(c, 0, "o", 1, zl, nke("foo6", "m", null), nke("foo6", "r", "m"), nke("foo6", null, "r"));
    runSplitRecoveryTest(c, 1, "o", 1, zl, nke("foo7", "m", null), nke("foo7", "r", "m"), nke("foo7", null, "r"));
    // run test for table w/ three tablets, run test on first
    runSplitRecoveryTest(c, 0, "g", 0, zl, nke("foo8", "m", null), nke("foo8", "r", "m"), nke("foo8", null, "r"));
    runSplitRecoveryTest(c, 1, "g", 0, zl, nke("foo9", "m", null), nke("foo9", "r", "m"), nke("foo9", null, "r"));
    // run test for table w/ three tablets, run test on last tablet
    runSplitRecoveryTest(c, 0, "w", 2, zl, nke("fooa", "m", null), nke("fooa", "r", "m"), nke("fooa", null, "r"));
    runSplitRecoveryTest(c, 1, "w", 2, zl, nke("foob", "m", null), nke("foob", "r", "m"), nke("foob", null, "r"));
}
Also used : AccumuloServerContext(org.apache.accumulo.server.AccumuloServerContext) Instance(org.apache.accumulo.core.client.Instance) TServerInstance(org.apache.accumulo.server.master.state.TServerInstance) HdfsZooInstance(org.apache.accumulo.server.client.HdfsZooInstance) IZooReaderWriter(org.apache.accumulo.fate.zookeeper.IZooReaderWriter) LockWatcher(org.apache.accumulo.fate.zookeeper.ZooLock.LockWatcher) ServerConfigurationFactory(org.apache.accumulo.server.conf.ServerConfigurationFactory) LockLossReason(org.apache.accumulo.fate.zookeeper.ZooLock.LockLossReason) ZooLock(org.apache.accumulo.server.zookeeper.ZooLock)

Example 10 with AccumuloServerContext

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

the class Initialize method execute.

@Override
public void execute(final String[] args) {
    Opts opts = new Opts();
    opts.parseArgs("accumulo init", args);
    try {
        zoo = ZooReaderWriter.getInstance();
        AccumuloConfiguration acuConf = SiteConfiguration.getInstance();
        SecurityUtil.serverLogin(acuConf);
        Configuration conf = CachedConfiguration.getInstance();
        VolumeManager fs = VolumeManagerImpl.get(acuConf);
        if (opts.resetSecurity) {
            log.info("Resetting security on accumulo.");
            Instance instance = HdfsZooInstance.getInstance();
            AccumuloServerContext context = new AccumuloServerContext(instance, new ServerConfigurationFactory(instance));
            if (isInitialized(fs)) {
                if (!opts.forceResetSecurity) {
                    ConsoleReader c = getConsoleReader();
                    String userEnteredName = c.readLine("WARNING: This will remove all users from Accumulo! If you wish to proceed enter the instance name: ");
                    if (userEnteredName != null && !instance.getInstanceName().equals(userEnteredName)) {
                        log.error("Aborted reset security: Instance name did not match current instance.");
                        return;
                    }
                }
                final String rootUser = getRootUserName(opts);
                opts.rootpass = getRootPassword(opts, rootUser);
                initSecurity(context, opts, HdfsZooInstance.getInstance().getInstanceID(), rootUser);
            } else {
                log.error("FATAL: Attempted to reset security on accumulo before it was initialized");
            }
        }
        if (opts.addVolumes) {
            addVolumes(fs);
        }
        if (!opts.resetSecurity && !opts.addVolumes)
            if (!doInit(opts, conf, fs))
                System.exit(-1);
    } catch (Exception e) {
        log.error("Fatal exception", e);
        throw new RuntimeException(e);
    }
}
Also used : VolumeManager(org.apache.accumulo.server.fs.VolumeManager) AccumuloServerContext(org.apache.accumulo.server.AccumuloServerContext) Configuration(org.apache.hadoop.conf.Configuration) VolumeConfiguration(org.apache.accumulo.core.volume.VolumeConfiguration) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) SiteConfiguration(org.apache.accumulo.core.conf.SiteConfiguration) CachedConfiguration(org.apache.accumulo.core.util.CachedConfiguration) DefaultConfiguration(org.apache.accumulo.core.conf.DefaultConfiguration) ConsoleReader(jline.console.ConsoleReader) Instance(org.apache.accumulo.core.client.Instance) HdfsZooInstance(org.apache.accumulo.server.client.HdfsZooInstance) ServerConfigurationFactory(org.apache.accumulo.server.conf.ServerConfigurationFactory) ThriftSecurityException(org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) KeeperException(org.apache.zookeeper.KeeperException) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration)

Aggregations

AccumuloServerContext (org.apache.accumulo.server.AccumuloServerContext)38 Test (org.junit.Test)20 ServerConfigurationFactory (org.apache.accumulo.server.conf.ServerConfigurationFactory)17 Instance (org.apache.accumulo.core.client.Instance)16 KeyExtent (org.apache.accumulo.core.data.impl.KeyExtent)12 TServerInstance (org.apache.accumulo.server.master.state.TServerInstance)12 HashMap (java.util.HashMap)9 TKeyExtent (org.apache.accumulo.core.data.thrift.TKeyExtent)8 HdfsZooInstance (org.apache.accumulo.server.client.HdfsZooInstance)8 ArrayList (java.util.ArrayList)7 VolumeManager (org.apache.accumulo.server.fs.VolumeManager)7 Connector (org.apache.accumulo.core.client.Connector)6 GCStatus (org.apache.accumulo.core.gc.thrift.GCStatus)6 Map (java.util.Map)5 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)5 GcCycleStats (org.apache.accumulo.core.gc.thrift.GcCycleStats)5 TabletServerStatus (org.apache.accumulo.core.master.thrift.TabletServerStatus)5 WalStateManager (org.apache.accumulo.server.log.WalStateManager)5 LiveTServerSet (org.apache.accumulo.server.master.LiveTServerSet)5 TabletMigration (org.apache.accumulo.server.master.state.TabletMigration)5