Search in sources :

Example 16 with ServerContext

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

the class HostRegexTableLoadBalancerReconfigurationTest method testConfigurationChanges.

@Test
public void testConfigurationChanges() {
    ServerContext context1 = createMockContext();
    replay(context1);
    final TestServerConfigurationFactory factory = new TestServerConfigurationFactory(context1);
    ServerContext context2 = createMockContext();
    expect(context2.getConfiguration()).andReturn(factory.getSystemConfiguration()).anyTimes();
    expect(context2.getTableConfiguration(FOO.getId())).andReturn(factory.getTableConfiguration(FOO.getId())).anyTimes();
    expect(context2.getTableConfiguration(BAR.getId())).andReturn(factory.getTableConfiguration(BAR.getId())).anyTimes();
    expect(context2.getTableConfiguration(BAZ.getId())).andReturn(factory.getTableConfiguration(BAZ.getId())).anyTimes();
    replay(context2);
    init(context2);
    Map<KeyExtent, TServerInstance> unassigned = new HashMap<>();
    for (List<KeyExtent> extents : tableExtents.values()) {
        for (KeyExtent ke : extents) {
            unassigned.put(ke, null);
        }
    }
    this.getAssignments(Collections.unmodifiableSortedMap(allTabletServers), Collections.unmodifiableMap(unassigned), assignments);
    assertEquals(15, 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())) {
                fail("Assignment failure. " + e.getKey() + " and " + e2.getKey() + " are assigned to the same host: " + e.getValue());
            }
        }
    }
    // Ensure assignments are correct
    for (Entry<KeyExtent, TServerInstance> e : assignments.entrySet()) {
        if (!tabletInBounds(e.getKey(), e.getValue())) {
            fail("tablet not in bounds: " + e.getKey() + " -> " + e.getValue().getHost());
        }
    }
    Set<KeyExtent> migrations = new HashSet<>();
    List<TabletMigration> migrationsOut = new ArrayList<>();
    // Wait to trigger the out of bounds check which will call our version of
    // getOnlineTabletsForTable
    UtilWaitThread.sleep(3000);
    this.balance(Collections.unmodifiableSortedMap(allTabletServers), migrations, migrationsOut);
    assertEquals(0, migrationsOut.size());
    // Change property, simulate call by TableConfWatcher
    ((ConfigurationCopy) factory.getSystemConfiguration()).set(HostRegexTableLoadBalancer.HOST_BALANCER_PREFIX + BAR.getTableName(), "r01.*");
    // Wait to trigger the out of bounds check and the repool check
    UtilWaitThread.sleep(10000);
    this.balance(Collections.unmodifiableSortedMap(allTabletServers), migrations, migrationsOut);
    assertEquals(5, migrationsOut.size());
    for (TabletMigration migration : migrationsOut) {
        assertTrue(migration.newServer.getHost().startsWith("192.168.0.1") || migration.newServer.getHost().startsWith("192.168.0.2") || migration.newServer.getHost().startsWith("192.168.0.3") || migration.newServer.getHost().startsWith("192.168.0.4") || migration.newServer.getHost().startsWith("192.168.0.5"));
    }
}
Also used : ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) TabletMigration(org.apache.accumulo.server.master.state.TabletMigration) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) ServerContext(org.apache.accumulo.server.ServerContext) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 17 with ServerContext

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

the class BulkImporterTest method testFindOverlappingTablets.

@Test
public void testFindOverlappingTablets() throws Exception {
    MockTabletLocator locator = new MockTabletLocator();
    FileSystem fs = FileSystem.getLocal(new Configuration());
    ServerContext context = MockServerContext.get();
    EasyMock.replay(context);
    String file = "target/testFile.rf";
    fs.delete(new Path(file), true);
    FileSKVWriter writer = FileOperations.getInstance().newWriterBuilder().forFile(file, fs, fs.getConf(), CryptoServiceFactory.newDefaultInstance()).withTableConfiguration(context.getConfiguration()).build();
    writer.startDefaultLocalityGroup();
    Value empty = new Value();
    writer.append(new Key("a", "cf", "cq"), empty);
    writer.append(new Key("a", "cf", "cq1"), empty);
    writer.append(new Key("a", "cf", "cq2"), empty);
    writer.append(new Key("a", "cf", "cq3"), empty);
    writer.append(new Key("a", "cf", "cq4"), empty);
    writer.append(new Key("a", "cf", "cq5"), empty);
    writer.append(new Key("d", "cf", "cq"), empty);
    writer.append(new Key("d", "cf", "cq1"), empty);
    writer.append(new Key("d", "cf", "cq2"), empty);
    writer.append(new Key("d", "cf", "cq3"), empty);
    writer.append(new Key("d", "cf", "cq4"), empty);
    writer.append(new Key("d", "cf", "cq5"), empty);
    writer.append(new Key("dd", "cf", "cq1"), empty);
    writer.append(new Key("ichabod", "cf", "cq"), empty);
    writer.append(new Key("icky", "cf", "cq1"), empty);
    writer.append(new Key("iffy", "cf", "cq2"), empty);
    writer.append(new Key("internal", "cf", "cq3"), empty);
    writer.append(new Key("is", "cf", "cq4"), empty);
    writer.append(new Key("iterator", "cf", "cq5"), empty);
    writer.append(new Key("xyzzy", "cf", "cq"), empty);
    writer.close();
    try (var vm = VolumeManagerImpl.getLocalForTesting("file:///")) {
        List<TabletLocation> overlaps = BulkImporter.findOverlappingTablets(context, vm, locator, new Path(file));
        assertEquals(5, overlaps.size());
        Collections.sort(overlaps);
        assertEquals(new KeyExtent(tableId, new Text("a"), null), overlaps.get(0).tablet_extent);
        assertEquals(new KeyExtent(tableId, new Text("d"), new Text("cm")), overlaps.get(1).tablet_extent);
        assertEquals(new KeyExtent(tableId, new Text("dm"), new Text("d")), overlaps.get(2).tablet_extent);
        assertEquals(new KeyExtent(tableId, new Text("j"), new Text("i")), overlaps.get(3).tablet_extent);
        assertEquals(new KeyExtent(tableId, null, new Text("l")), overlaps.get(4).tablet_extent);
        List<TabletLocation> overlaps2 = BulkImporter.findOverlappingTablets(context, vm, locator, new Path(file), new KeyExtent(tableId, new Text("h"), new Text("b")));
        assertEquals(3, overlaps2.size());
        assertEquals(new KeyExtent(tableId, new Text("d"), new Text("cm")), overlaps2.get(0).tablet_extent);
        assertEquals(new KeyExtent(tableId, new Text("dm"), new Text("d")), overlaps2.get(1).tablet_extent);
        assertEquals(new KeyExtent(tableId, new Text("j"), new Text("i")), overlaps2.get(2).tablet_extent);
        assertEquals(locator.invalidated, 1);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) FileSKVWriter(org.apache.accumulo.core.file.FileSKVWriter) Text(org.apache.hadoop.io.Text) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) MockServerContext(org.apache.accumulo.server.MockServerContext) ServerContext(org.apache.accumulo.server.ServerContext) TabletLocation(org.apache.accumulo.core.clientImpl.TabletLocator.TabletLocation) FileSystem(org.apache.hadoop.fs.FileSystem) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 18 with ServerContext

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

the class Upgrader9to10 method getOldCandidates.

/**
 * Return path of the file from old delete markers
 */
private Iterator<String> getOldCandidates(ServerContext context, String tableName) throws TableNotFoundException {
    Range range = DeletesSection.getRange();
    Scanner scanner = context.createScanner(tableName, Authorizations.EMPTY);
    scanner.setRange(range);
    return StreamSupport.stream(scanner.spliterator(), false).filter(entry -> !entry.getValue().equals(UPGRADED)).map(entry -> entry.getKey().getRow().toString().substring(OLD_DELETE_PREFIX.length())).iterator();
}
Also used : TableId(org.apache.accumulo.core.data.TableId) TabletMutatorBase(org.apache.accumulo.server.metadata.TabletMutatorBase) RootGcCandidates(org.apache.accumulo.server.metadata.RootGcCandidates) FileSystem(org.apache.hadoop.fs.FileSystem) LoggerFactory(org.slf4j.LoggerFactory) MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) Mutation(org.apache.accumulo.core.data.Mutation) FileStatus(org.apache.hadoop.fs.FileStatus) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) ZROOT_TABLET(org.apache.accumulo.core.metadata.RootTable.ZROOT_TABLET) FileOperations(org.apache.accumulo.core.file.FileOperations) Map(java.util.Map) RootTable(org.apache.accumulo.core.metadata.RootTable) Path(org.apache.hadoop.fs.Path) Value(org.apache.accumulo.core.data.Value) MetadataTime(org.apache.accumulo.core.metadata.schema.MetadataTime) TablePropUtil(org.apache.accumulo.server.util.TablePropUtil) Property(org.apache.accumulo.core.conf.Property) SimpleCompactionDispatcher(org.apache.accumulo.core.spi.compaction.SimpleCompactionDispatcher) LocationType(org.apache.accumulo.core.metadata.schema.TabletMetadata.LocationType) Ample(org.apache.accumulo.core.metadata.schema.Ample) VolumeManager(org.apache.accumulo.server.fs.VolumeManager) Collection(java.util.Collection) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) FileSKVIterator(org.apache.accumulo.core.file.FileSKVIterator) TimeType(org.apache.accumulo.core.client.admin.TimeType) SkewedKeyValue(org.apache.accumulo.core.metadata.schema.MetadataSchema.DeletesSection.SkewedKeyValue) AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) UncheckedIOException(java.io.UncheckedIOException) Objects(java.util.Objects) DeletesSection(org.apache.accumulo.core.metadata.schema.MetadataSchema.DeletesSection) List(java.util.List) NodeExistsPolicy(org.apache.accumulo.fate.zookeeper.ZooUtil.NodeExistsPolicy) DeprecatedPropertyUtil(org.apache.accumulo.core.conf.DeprecatedPropertyUtil) Entry(java.util.Map.Entry) ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) Scanner(org.apache.accumulo.core.client.Scanner) DIRECTORY_COLUMN(org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ServerColumnFamily.DIRECTORY_COLUMN) DataFileValue(org.apache.accumulo.core.metadata.schema.DataFileValue) HostAndPort(org.apache.accumulo.core.util.HostAndPort) DataFileColumnFamily(org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.DataFileColumnFamily) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EMPTY_TEXT(org.apache.accumulo.server.util.MetadataTableUtil.EMPTY_TEXT) Key(org.apache.accumulo.core.data.Key) SystemPropUtil(org.apache.accumulo.server.util.SystemPropUtil) StreamSupport(java.util.stream.StreamSupport) TabletFile(org.apache.accumulo.core.metadata.TabletFile) ZooReaderWriter(org.apache.accumulo.fate.zookeeper.ZooReaderWriter) NodeMissingPolicy(org.apache.accumulo.fate.zookeeper.ZooUtil.NodeMissingPolicy) ZooConfiguration(org.apache.accumulo.server.conf.ZooConfiguration) GcVolumeUtil(org.apache.accumulo.server.gc.GcVolumeUtil) LogEntry(org.apache.accumulo.core.tabletserver.log.LogEntry) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) KeeperException(org.apache.zookeeper.KeeperException) UTF_8(java.nio.charset.StandardCharsets.UTF_8) ServerContext(org.apache.accumulo.server.ServerContext) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) IOException(java.io.IOException) Constants(org.apache.accumulo.core.Constants) Authorizations(org.apache.accumulo.core.security.Authorizations) AccumuloException(org.apache.accumulo.core.client.AccumuloException) Range(org.apache.accumulo.core.data.Range) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) RootTabletMetadata(org.apache.accumulo.core.metadata.schema.RootTabletMetadata) ZROOT_TABLET_GC_CANDIDATES(org.apache.accumulo.core.metadata.RootTable.ZROOT_TABLET_GC_CANDIDATES) Preconditions(com.google.common.base.Preconditions) BatchWriter(org.apache.accumulo.core.client.BatchWriter) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Scanner(org.apache.accumulo.core.client.Scanner) Range(org.apache.accumulo.core.data.Range)

Example 19 with ServerContext

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

the class Monitor method fetchData.

public void fetchData() {
    ServerContext context = getContext();
    double totalIngestRate = 0.;
    double totalIngestByteRate = 0.;
    double totalQueryRate = 0.;
    double totalQueryByteRate = 0.;
    double totalScanRate = 0.;
    long totalEntries = 0;
    int totalTabletCount = 0;
    long totalHoldTime = 0;
    long totalLookups = 0;
    boolean retry = true;
    // only recalc every so often
    long currentTime = System.currentTimeMillis();
    if (currentTime - lastRecalc.get() < REFRESH_TIME * 1000) {
        return;
    }
    // try to begin fetching; return if unsuccessful (because another thread is already fetching)
    if (!fetching.compareAndSet(false, true)) {
        return;
    }
    // Otherwise, we'll never release the lock by unsetting 'fetching' in the the finally block
    try {
        while (retry) {
            ManagerClientService.Iface client = null;
            try {
                client = ManagerClient.getConnection(context);
                if (client != null) {
                    mmi = client.getManagerStats(TraceUtil.traceInfo(), context.rpcCreds());
                    retry = false;
                } else {
                    mmi = null;
                    log.error("Unable to get info from Manager");
                }
                gcStatus = fetchGcStatus();
            } catch (Exception e) {
                mmi = null;
                log.info("Error fetching stats: ", e);
            } finally {
                if (client != null) {
                    ManagerClient.close(client, context);
                }
            }
            if (mmi == null) {
                sleepUninterruptibly(1, TimeUnit.SECONDS);
            }
        }
        if (mmi != null) {
            int majorCompactions = 0;
            int minorCompactions = 0;
            lookupRateTracker.startingUpdates();
            indexCacheHitTracker.startingUpdates();
            indexCacheRequestTracker.startingUpdates();
            dataCacheHitTracker.startingUpdates();
            dataCacheRequestTracker.startingUpdates();
            for (TabletServerStatus server : mmi.tServerInfo) {
                TableInfo summary = TableInfoUtil.summarizeTableStats(server);
                totalIngestRate += summary.ingestRate;
                totalIngestByteRate += summary.ingestByteRate;
                totalQueryRate += summary.queryRate;
                totalScanRate += summary.scanRate;
                totalQueryByteRate += summary.queryByteRate;
                totalEntries += summary.recs;
                totalHoldTime += server.holdTime;
                totalLookups += server.lookups;
                majorCompactions += summary.majors.running;
                minorCompactions += summary.minors.running;
                lookupRateTracker.updateTabletServer(server.name, server.lastContact, server.lookups);
                indexCacheHitTracker.updateTabletServer(server.name, server.lastContact, server.indexCacheHits);
                indexCacheRequestTracker.updateTabletServer(server.name, server.lastContact, server.indexCacheRequest);
                dataCacheHitTracker.updateTabletServer(server.name, server.lastContact, server.dataCacheHits);
                dataCacheRequestTracker.updateTabletServer(server.name, server.lastContact, server.dataCacheRequest);
            }
            lookupRateTracker.finishedUpdating();
            indexCacheHitTracker.finishedUpdating();
            indexCacheRequestTracker.finishedUpdating();
            dataCacheHitTracker.finishedUpdating();
            dataCacheRequestTracker.finishedUpdating();
            int totalTables = 0;
            for (TableInfo tInfo : mmi.tableMap.values()) {
                totalTabletCount += tInfo.tablets;
                totalTables++;
            }
            this.totalIngestRate = totalIngestRate;
            this.totalTables = totalTables;
            totalIngestByteRate = totalIngestByteRate / 1000000.0;
            this.totalQueryRate = totalQueryRate;
            this.totalScanRate = totalScanRate;
            totalQueryByteRate = totalQueryByteRate / 1000000.0;
            this.totalEntries = totalEntries;
            this.totalTabletCount = totalTabletCount;
            this.totalHoldTime = totalHoldTime;
            this.totalLookups = totalLookups;
            ingestRateOverTime.add(new Pair<>(currentTime, totalIngestRate));
            ingestByteRateOverTime.add(new Pair<>(currentTime, totalIngestByteRate));
            double totalLoad = 0.;
            for (TabletServerStatus status : mmi.tServerInfo) {
                if (status != null) {
                    totalLoad += status.osLoad;
                }
            }
            loadOverTime.add(new Pair<>(currentTime, totalLoad));
            minorCompactionsOverTime.add(new Pair<>(currentTime, minorCompactions));
            majorCompactionsOverTime.add(new Pair<>(currentTime, majorCompactions));
            lookupsOverTime.add(new Pair<>(currentTime, lookupRateTracker.calculateRate()));
            queryRateOverTime.add(new Pair<>(currentTime, (long) totalQueryRate));
            queryByteRateOverTime.add(new Pair<>(currentTime, totalQueryByteRate));
            scanRateOverTime.add(new Pair<>(currentTime, (long) totalScanRate));
            calcCacheHitRate(indexCacheHitRateOverTime, currentTime, indexCacheHitTracker, indexCacheRequestTracker);
            calcCacheHitRate(dataCacheHitRateOverTime, currentTime, dataCacheHitTracker, dataCacheRequestTracker);
        }
        try {
            this.problemSummary = ProblemReports.getInstance(context).summarize();
            this.problemException = null;
        } catch (Exception e) {
            log.info("Failed to obtain problem reports ", e);
            this.problemSummary = Collections.emptyMap();
            this.problemException = e;
        }
        // check for compaction coordinator host and only notify its discovery
        Optional<HostAndPort> previousHost;
        if (System.nanoTime() - coordinatorCheckNanos > fetchTimeNanos) {
            previousHost = coordinatorHost;
            coordinatorHost = ExternalCompactionUtil.findCompactionCoordinator(context);
            coordinatorCheckNanos = System.nanoTime();
            if (previousHost.isEmpty() && coordinatorHost.isPresent())
                log.info("External Compaction Coordinator found at {}", coordinatorHost.get());
        }
    } finally {
        if (coordinatorClient != null) {
            ThriftUtil.returnClient(coordinatorClient, context);
            coordinatorClient = null;
        }
        lastRecalc.set(currentTime);
        // stop fetching; log an error if this thread wasn't already fetching
        if (!fetching.compareAndSet(true, false)) {
            throw new AssertionError("Not supposed to happen; somebody broke this code");
        }
    }
}
Also used : ManagerClientService(org.apache.accumulo.core.manager.thrift.ManagerClientService) KeeperException(org.apache.zookeeper.KeeperException) UnknownHostException(java.net.UnknownHostException) HostAndPort(org.apache.accumulo.core.util.HostAndPort) ServerContext(org.apache.accumulo.server.ServerContext) TableInfo(org.apache.accumulo.core.master.thrift.TableInfo) TabletServerStatus(org.apache.accumulo.core.master.thrift.TabletServerStatus)

Example 20 with ServerContext

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

the class Monitor method fetchGcStatus.

private GCStatus fetchGcStatus() {
    ServerContext context = getContext();
    GCStatus result = null;
    HostAndPort address = null;
    try {
        // Read the gc location from its lock
        ZooReaderWriter zk = context.getZooReaderWriter();
        var path = ServiceLock.path(context.getZooKeeperRoot() + Constants.ZGC_LOCK);
        List<String> locks = ServiceLock.validateAndSort(path, zk.getChildren(path.toString()));
        if (locks != null && !locks.isEmpty()) {
            address = new ServerServices(new String(zk.getData(path + "/" + locks.get(0)), UTF_8)).getAddress(Service.GC_CLIENT);
            GCMonitorService.Client client = ThriftUtil.getClient(new GCMonitorService.Client.Factory(), address, context);
            try {
                result = client.getStatus(TraceUtil.traceInfo(), context.rpcCreds());
            } finally {
                ThriftUtil.returnClient(client, context);
            }
        }
    } catch (Exception ex) {
        log.warn("Unable to contact the garbage collector at " + address, ex);
    }
    return result;
}
Also used : ServerServices(org.apache.accumulo.core.util.ServerServices) ZooReaderWriter(org.apache.accumulo.fate.zookeeper.ZooReaderWriter) GCStatus(org.apache.accumulo.core.gc.thrift.GCStatus) GCMonitorService(org.apache.accumulo.core.gc.thrift.GCMonitorService) KeeperException(org.apache.zookeeper.KeeperException) UnknownHostException(java.net.UnknownHostException) HostAndPort(org.apache.accumulo.core.util.HostAndPort) ServerContext(org.apache.accumulo.server.ServerContext) ManagerClient(org.apache.accumulo.core.clientImpl.ManagerClient) Client(org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Client)

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