Search in sources :

Example 11 with ExternalCompactionId

use of org.apache.accumulo.core.metadata.schema.ExternalCompactionId in project accumulo by apache.

the class Tablet method split.

public TreeMap<KeyExtent, TabletData> split(byte[] sp) throws IOException {
    if (sp != null && extent.endRow() != null && extent.endRow().equals(new Text(sp))) {
        throw new IllegalArgumentException("Attempting to split on EndRow " + extent.endRow() + " for " + extent);
    }
    if (sp != null && sp.length > tableConfiguration.getAsBytes(Property.TABLE_MAX_END_ROW_SIZE)) {
        String msg = "Cannot split tablet " + extent + ", selected split point too long.  Length :  " + sp.length;
        log.warn(msg);
        throw new IOException(msg);
    }
    if (extent.isRootTablet()) {
        String msg = "Cannot split root tablet";
        log.warn(msg);
        throw new RuntimeException(msg);
    }
    try {
        initiateClose(true);
    } catch (IllegalStateException ise) {
        log.debug("File {} not splitting : {}", extent, ise.getMessage());
        return null;
    }
    // obtain this info outside of synch block since it will involve opening
    // the map files... it is ok if the set of map files changes, because
    // this info is used for optimization... it is ok if map files are missing
    // from the set... can still query and insert into the tablet while this
    // map file operation is happening
    Map<TabletFile, FileUtil.FileInfo> firstAndLastRows = FileUtil.tryToGetFirstAndLastRows(context, getDatafileManager().getFiles());
    synchronized (this) {
        // java needs tuples ...
        TreeMap<KeyExtent, TabletData> newTablets = new TreeMap<>();
        long t1 = System.currentTimeMillis();
        // choose a split point
        SplitRowSpec splitPoint;
        if (sp == null) {
            splitPoint = findSplitRow(getDatafileManager().getFiles());
        } else {
            Text tsp = new Text(sp);
            splitPoint = new SplitRowSpec(FileUtil.estimatePercentageLTE(context, chooseTabletDir(), extent.prevEndRow(), extent.endRow(), getDatafileManager().getFiles(), tsp), tsp);
        }
        if (splitPoint == null || splitPoint.row == null) {
            log.info("had to abort split because splitRow was null");
            closeState = CloseState.OPEN;
            return null;
        }
        closeState = CloseState.CLOSING;
        completeClose(true, false);
        Text midRow = splitPoint.row;
        double splitRatio = splitPoint.splitRatio;
        KeyExtent low = new KeyExtent(extent.tableId(), midRow, extent.prevEndRow());
        KeyExtent high = new KeyExtent(extent.tableId(), extent.endRow(), midRow);
        String lowDirectoryName = createTabletDirectoryName(context, midRow);
        // write new tablet information to MetadataTable
        SortedMap<StoredTabletFile, DataFileValue> lowDatafileSizes = new TreeMap<>();
        SortedMap<StoredTabletFile, DataFileValue> highDatafileSizes = new TreeMap<>();
        List<StoredTabletFile> highDatafilesToRemove = new ArrayList<>();
        MetadataTableUtil.splitDatafiles(midRow, splitRatio, firstAndLastRows, getDatafileManager().getDatafileSizes(), lowDatafileSizes, highDatafileSizes, highDatafilesToRemove);
        log.debug("Files for low split {} {}", low, lowDatafileSizes.keySet());
        log.debug("Files for high split {} {}", high, highDatafileSizes.keySet());
        MetadataTime time = tabletTime.getMetadataTime();
        HashSet<ExternalCompactionId> ecids = new HashSet<>();
        compactable.getExternalCompactionIds(ecids::add);
        MetadataTableUtil.splitTablet(high, extent.prevEndRow(), splitRatio, getTabletServer().getContext(), getTabletServer().getLock(), ecids);
        ManagerMetadataUtil.addNewTablet(getTabletServer().getContext(), low, lowDirectoryName, getTabletServer().getTabletSession(), lowDatafileSizes, bulkImported, time, lastFlushID, lastCompactID, getTabletServer().getLock());
        MetadataTableUtil.finishSplit(high, highDatafileSizes, highDatafilesToRemove, getTabletServer().getContext(), getTabletServer().getLock());
        TabletLogger.split(extent, low, high, getTabletServer().getTabletSession());
        newTablets.put(high, new TabletData(dirName, highDatafileSizes, time, lastFlushID, lastCompactID, lastLocation, bulkImported));
        newTablets.put(low, new TabletData(lowDirectoryName, lowDatafileSizes, time, lastFlushID, lastCompactID, lastLocation, bulkImported));
        long t2 = System.currentTimeMillis();
        log.debug(String.format("offline split time : %6.2f secs", (t2 - t1) / 1000.0));
        closeState = CloseState.COMPLETE;
        return newTablets;
    }
}
Also used : ExternalCompactionId(org.apache.accumulo.core.metadata.schema.ExternalCompactionId) ArrayList(java.util.ArrayList) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) MapFileInfo(org.apache.accumulo.core.dataImpl.thrift.MapFileInfo) StoredTabletFile(org.apache.accumulo.core.metadata.StoredTabletFile) TabletFile(org.apache.accumulo.core.metadata.TabletFile) HashSet(java.util.HashSet) DataFileValue(org.apache.accumulo.core.metadata.schema.DataFileValue) Text(org.apache.hadoop.io.Text) IOException(java.io.IOException) TreeMap(java.util.TreeMap) StoredTabletFile(org.apache.accumulo.core.metadata.StoredTabletFile) MetadataTime(org.apache.accumulo.core.metadata.schema.MetadataTime)

Example 12 with ExternalCompactionId

use of org.apache.accumulo.core.metadata.schema.ExternalCompactionId in project accumulo by apache.

the class Tablet method removeOldTemporaryFiles.

private void removeOldTemporaryFiles(Map<ExternalCompactionId, ExternalCompactionMetadata> externalCompactions) {
    // remove any temporary files created by a previous tablet server
    try {
        var extCompactionFiles = externalCompactions.values().stream().map(ecMeta -> ecMeta.getCompactTmpName().getPath()).collect(Collectors.toSet());
        for (Volume volume : getTabletServer().getVolumeManager().getVolumes()) {
            String dirUri = volume.getBasePath() + Constants.HDFS_TABLES_DIR + Path.SEPARATOR + extent.tableId() + Path.SEPARATOR + dirName;
            for (FileStatus tmp : volume.getFileSystem().globStatus(new Path(dirUri, "*_tmp"))) {
                if (extCompactionFiles.contains(tmp.getPath())) {
                    continue;
                }
                try {
                    log.debug("Removing old temp file {}", tmp.getPath());
                    volume.getFileSystem().delete(tmp.getPath(), false);
                } catch (IOException ex) {
                    log.error("Unable to remove old temp file " + tmp.getPath() + ": " + ex);
                }
            }
        }
    } catch (IOException ex) {
        log.error("Error scanning for old temp files", ex);
    }
}
Also used : ByteSequence(org.apache.accumulo.core.data.ByteSequence) VolumeChooserEnvironmentImpl(org.apache.accumulo.server.fs.VolumeChooserEnvironmentImpl) TooManyFilesException(org.apache.accumulo.server.fs.TooManyFilesException) Text(org.apache.hadoop.io.Text) MetadataTableUtil(org.apache.accumulo.server.util.MetadataTableUtil) FileStatus(org.apache.hadoop.fs.FileStatus) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) ExternalCompactionId(org.apache.accumulo.core.metadata.schema.ExternalCompactionId) Map(java.util.Map) MapFileInfo(org.apache.accumulo.core.dataImpl.thrift.MapFileInfo) MetadataTime(org.apache.accumulo.core.metadata.schema.MetadataTime) DfsLogger(org.apache.accumulo.tserver.log.DfsLogger) BulkImportState(org.apache.accumulo.core.master.thrift.BulkImportState) Property(org.apache.accumulo.core.conf.Property) TabletServer(org.apache.accumulo.tserver.TabletServer) TableState(org.apache.accumulo.core.manager.state.tables.TableState) Compactable(org.apache.accumulo.tserver.compactions.Compactable) DecoderException(org.apache.commons.codec.DecoderException) TabletStats(org.apache.accumulo.core.tabletserver.thrift.TabletStats) Deriver(org.apache.accumulo.core.conf.AccumuloConfiguration.Deriver) Set(java.util.Set) Stream(java.util.stream.Stream) Violations(org.apache.accumulo.core.constraints.Violations) UtilWaitThread.sleepUninterruptibly(org.apache.accumulo.fate.util.UtilWaitThread.sleepUninterruptibly) TabletFiles(org.apache.accumulo.server.fs.VolumeUtil.TabletFiles) ProblemType(org.apache.accumulo.server.problems.ProblemType) ProblemReports(org.apache.accumulo.server.problems.ProblemReports) ReplicationTableUtil(org.apache.accumulo.server.util.ReplicationTableUtil) DurabilityImpl(org.apache.accumulo.core.clientImpl.DurabilityImpl) SortedKeyValueIterator(org.apache.accumulo.core.iterators.SortedKeyValueIterator) ArrayList(java.util.ArrayList) TabletMetadata(org.apache.accumulo.core.metadata.schema.TabletMetadata) ColumnUpdate(org.apache.accumulo.core.data.ColumnUpdate) StoredTabletFile(org.apache.accumulo.core.metadata.StoredTabletFile) Key(org.apache.accumulo.core.data.Key) TabletFile(org.apache.accumulo.core.metadata.TabletFile) ServerContext(org.apache.accumulo.server.ServerContext) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) IOException(java.io.IOException) TabletTime(org.apache.accumulo.server.tablets.TabletTime) Range(org.apache.accumulo.core.data.Range) AtomicLong(java.util.concurrent.atomic.AtomicLong) TreeMap(java.util.TreeMap) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) ExternalCompactionMetadata(org.apache.accumulo.core.metadata.schema.ExternalCompactionMetadata) Preconditions(com.google.common.base.Preconditions) YieldCallback(org.apache.accumulo.core.iterators.YieldCallback) UserCompactionUtils(org.apache.accumulo.core.clientImpl.UserCompactionUtils) FileUtil(org.apache.accumulo.server.util.FileUtil) LoggerFactory(org.slf4j.LoggerFactory) Status(org.apache.accumulo.server.replication.proto.Replication.Status) MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) TabletLogger(org.apache.accumulo.core.logging.TabletLogger) Mutation(org.apache.accumulo.core.data.Mutation) VolumeUtil(org.apache.accumulo.server.fs.VolumeUtil) ScanParameters(org.apache.accumulo.tserver.scan.ScanParameters) LocalityGroupUtil(org.apache.accumulo.core.util.LocalityGroupUtil) FileOperations(org.apache.accumulo.core.file.FileOperations) ByteArrayInputStream(java.io.ByteArrayInputStream) Path(org.apache.hadoop.fs.Path) Value(org.apache.accumulo.core.data.Value) ConstraintChecker(org.apache.accumulo.tserver.constraints.ConstraintChecker) ProblemReport(org.apache.accumulo.server.problems.ProblemReport) ConditionChecker(org.apache.accumulo.tserver.ConditionCheckerContext.ConditionChecker) InMemoryMap(org.apache.accumulo.tserver.InMemoryMap) Span(io.opentelemetry.api.trace.Span) Operation(org.apache.accumulo.tserver.TabletStatsKeeper.Operation) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Durability(org.apache.accumulo.core.client.Durability) Collectors(java.util.stream.Collectors) SourceSwitchingIterator(org.apache.accumulo.core.iteratorsImpl.system.SourceSwitchingIterator) FileNotFoundException(java.io.FileNotFoundException) TabletStatsKeeper(org.apache.accumulo.tserver.TabletStatsKeeper) List(java.util.List) TableConfiguration(org.apache.accumulo.server.conf.TableConfiguration) Pair(org.apache.accumulo.core.util.Pair) ManagerMetadataUtil(org.apache.accumulo.server.util.ManagerMetadataUtil) Entry(java.util.Map.Entry) Optional(java.util.Optional) TraceUtil(org.apache.accumulo.core.trace.TraceUtil) SortedMap(java.util.SortedMap) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) DataInputStream(java.io.DataInputStream) IterationInterruptedException(org.apache.accumulo.core.iteratorsImpl.system.IterationInterruptedException) DataFileValue(org.apache.accumulo.core.metadata.schema.DataFileValue) ProtobufUtil(org.apache.accumulo.core.protobuf.ProtobufUtil) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompactionConfig(org.apache.accumulo.core.client.admin.CompactionConfig) Hex(org.apache.commons.codec.binary.Hex) MinorCompactionReason(org.apache.accumulo.tserver.MinorCompactionReason) HashSet(java.util.HashSet) Volume(org.apache.accumulo.core.volume.Volume) TabletResourceManager(org.apache.accumulo.tserver.TabletServerResourceManager.TabletResourceManager) TabletServerMinCMetrics(org.apache.accumulo.tserver.metrics.TabletServerMinCMetrics) Objects.requireNonNull(java.util.Objects.requireNonNull) UniqueNameAllocator(org.apache.accumulo.server.tablets.UniqueNameAllocator) CompactionStats(org.apache.accumulo.server.compaction.CompactionStats) ServerColumnFamily(org.apache.accumulo.core.metadata.schema.MetadataSchema.TabletsSection.ServerColumnFamily) LogEntry(org.apache.accumulo.core.tabletserver.log.LogEntry) Logger(org.slf4j.Logger) ReentrantLock(java.util.concurrent.locks.ReentrantLock) KeeperException(org.apache.zookeeper.KeeperException) Scope(io.opentelemetry.context.Scope) UTF_8(java.nio.charset.StandardCharsets.UTF_8) ScanDispatch(org.apache.accumulo.core.spi.scan.ScanDispatch) VolumeChooserEnvironment(org.apache.accumulo.core.spi.fs.VolumeChooserEnvironment) Constants(org.apache.accumulo.core.Constants) Authorizations(org.apache.accumulo.core.security.Authorizations) TimeUnit(java.util.concurrent.TimeUnit) TservConstraintEnv(org.apache.accumulo.tserver.TservConstraintEnv) Collectors.toList(java.util.stream.Collectors.toList) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) ShutdownUtil(org.apache.accumulo.core.util.ShutdownUtil) Collections(java.util.Collections) ColumnType(org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType) Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) Volume(org.apache.accumulo.core.volume.Volume) IOException(java.io.IOException)

Example 13 with ExternalCompactionId

use of org.apache.accumulo.core.metadata.schema.ExternalCompactionId in project accumulo by apache.

the class ExternalCompactionUtil method getCompactionIdsRunningOnCompactors.

public static Collection<ExternalCompactionId> getCompactionIdsRunningOnCompactors(ClientContext context) {
    final ExecutorService executor = ThreadPools.createFixedThreadPool(16, "CompactorRunningCompactions", false);
    List<Future<ExternalCompactionId>> futures = new ArrayList<>();
    getCompactorAddrs(context).forEach((q, hp) -> {
        hp.forEach(hostAndPort -> {
            futures.add(executor.submit(() -> getRunningCompactionId(hostAndPort, context)));
        });
    });
    executor.shutdown();
    HashSet<ExternalCompactionId> runningIds = new HashSet<>();
    futures.forEach(future -> {
        try {
            ExternalCompactionId ceid = future.get();
            if (ceid != null) {
                runningIds.add(ceid);
            }
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }
    });
    return runningIds;
}
Also used : ExternalCompactionId(org.apache.accumulo.core.metadata.schema.ExternalCompactionId) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) HashSet(java.util.HashSet)

Example 14 with ExternalCompactionId

use of org.apache.accumulo.core.metadata.schema.ExternalCompactionId in project accumulo by apache.

the class CompactionCoordinatorTest method testCoordinatorRestartOneRunningCompaction.

@Test
public void testCoordinatorRestartOneRunningCompaction() throws Exception {
    PowerMock.resetAll();
    PowerMock.suppress(PowerMock.constructor(AbstractServer.class));
    PowerMock.suppress(PowerMock.methods(ThriftUtil.class, "returnClient"));
    PowerMock.suppress(PowerMock.methods(DeadCompactionDetector.class, "detectDeadCompactions", "detectDanglingFinalStateMarkers"));
    AccumuloConfiguration conf = PowerMock.createNiceMock(AccumuloConfiguration.class);
    ServerContext context = PowerMock.createNiceMock(ServerContext.class);
    TCredentials creds = PowerMock.createNiceMock(TCredentials.class);
    EasyMock.expect(context.rpcCreds()).andReturn(creds);
    CompactionFinalizer finalizer = PowerMock.createNiceMock(CompactionFinalizer.class);
    LiveTServerSet tservers = PowerMock.createNiceMock(LiveTServerSet.class);
    TServerInstance instance = PowerMock.createNiceMock(TServerInstance.class);
    HostAndPort tserverAddress = HostAndPort.fromString("localhost:9997");
    EasyMock.expect(instance.getHostAndPort()).andReturn(tserverAddress).anyTimes();
    EasyMock.expect(tservers.getCurrentServers()).andReturn(Sets.newHashSet(instance)).once();
    tservers.startListeningForTabletServerChanges();
    PowerMock.mockStatic(ExternalCompactionUtil.class);
    List<RunningCompaction> runningCompactions = new ArrayList<>();
    ExternalCompactionId eci = ExternalCompactionId.generate(UUID.randomUUID());
    TExternalCompactionJob job = PowerMock.createNiceMock(TExternalCompactionJob.class);
    EasyMock.expect(job.getExternalCompactionId()).andReturn(eci.toString()).anyTimes();
    TKeyExtent extent = new TKeyExtent();
    extent.setTable("1".getBytes());
    runningCompactions.add(new RunningCompaction(job, tserverAddress.toString(), "queue"));
    EasyMock.expect(ExternalCompactionUtil.getCompactionsRunningOnCompactors(context)).andReturn(runningCompactions);
    ServerAddress client = PowerMock.createNiceMock(ServerAddress.class);
    HostAndPort address = HostAndPort.fromString("localhost:10240");
    EasyMock.expect(client.getAddress()).andReturn(address).anyTimes();
    EasyMock.expect(instance.getHostPort()).andReturn("localhost:9997").anyTimes();
    TabletClientService.Client tsc = PowerMock.createNiceMock(TabletClientService.Client.class);
    TCompactionQueueSummary queueSummary = PowerMock.createNiceMock(TCompactionQueueSummary.class);
    EasyMock.expect(tsc.getCompactionQueueInfo(EasyMock.anyObject(), EasyMock.anyObject())).andReturn(Collections.singletonList(queueSummary)).anyTimes();
    EasyMock.expect(queueSummary.getQueue()).andReturn("R2DQ").anyTimes();
    EasyMock.expect(queueSummary.getPriority()).andReturn((short) 1).anyTimes();
    AuditedSecurityOperation security = PowerMock.createNiceMock(AuditedSecurityOperation.class);
    PowerMock.replayAll();
    TestCoordinator coordinator = new TestCoordinator(conf, finalizer, tservers, client, tsc, context, security);
    coordinator.resetInternals();
    assertEquals(0, coordinator.getQueues().size());
    assertEquals(0, coordinator.getIndex().size());
    assertEquals(0, coordinator.getRunning().size());
    coordinator.run();
    assertEquals(1, coordinator.getQueues().size());
    QueueAndPriority qp = QueueAndPriority.get("R2DQ".intern(), (short) 1);
    Map<Short, TreeSet<TServerInstance>> m = coordinator.getQueues().get("R2DQ".intern());
    assertNotNull(m);
    assertEquals(1, m.size());
    assertTrue(m.containsKey((short) 1));
    Set<TServerInstance> t = m.get((short) 1);
    assertNotNull(t);
    assertEquals(1, t.size());
    TServerInstance queuedTsi = t.iterator().next();
    assertEquals(instance.getHostPortSession(), queuedTsi.getHostPortSession());
    assertEquals(1, coordinator.getIndex().size());
    assertTrue(coordinator.getIndex().containsKey(queuedTsi));
    Set<QueueAndPriority> i = coordinator.getIndex().get(queuedTsi);
    assertEquals(1, i.size());
    assertEquals(qp, i.iterator().next());
    assertEquals(1, coordinator.getRunning().size());
    PowerMock.verifyAll();
    coordinator.resetInternals();
    coordinator.close();
}
Also used : ExternalCompactionId(org.apache.accumulo.core.metadata.schema.ExternalCompactionId) ThriftUtil(org.apache.accumulo.core.rpc.ThriftUtil) ArrayList(java.util.ArrayList) ServerAddress(org.apache.accumulo.server.rpc.ServerAddress) AuditedSecurityOperation(org.apache.accumulo.server.security.AuditedSecurityOperation) TCompactionQueueSummary(org.apache.accumulo.core.tabletserver.thrift.TCompactionQueueSummary) LiveTServerSet(org.apache.accumulo.server.manager.LiveTServerSet) HostAndPort(org.apache.accumulo.core.util.HostAndPort) Client(org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Client) TreeSet(java.util.TreeSet) TExternalCompactionJob(org.apache.accumulo.core.tabletserver.thrift.TExternalCompactionJob) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) TCredentials(org.apache.accumulo.core.securityImpl.thrift.TCredentials) RunningCompaction(org.apache.accumulo.core.util.compaction.RunningCompaction) TKeyExtent(org.apache.accumulo.core.dataImpl.thrift.TKeyExtent) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) AbstractServer(org.apache.accumulo.server.AbstractServer) ServerContext(org.apache.accumulo.server.ServerContext) TabletClientService(org.apache.accumulo.core.tabletserver.thrift.TabletClientService) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 15 with ExternalCompactionId

use of org.apache.accumulo.core.metadata.schema.ExternalCompactionId in project accumulo by apache.

the class CompactionCoordinatorTest method testGetCompactionJob.

@Test
public void testGetCompactionJob() throws Exception {
    PowerMock.resetAll();
    PowerMock.suppress(PowerMock.constructor(AbstractServer.class));
    PowerMock.suppress(PowerMock.methods(ThriftUtil.class, "returnClient"));
    PowerMock.suppress(PowerMock.methods(DeadCompactionDetector.class, "detectDeadCompactions", "detectDanglingFinalStateMarkers"));
    AccumuloConfiguration conf = PowerMock.createNiceMock(AccumuloConfiguration.class);
    ServerContext context = PowerMock.createNiceMock(ServerContext.class);
    TCredentials creds = PowerMock.createNiceMock(TCredentials.class);
    EasyMock.expect(context.rpcCreds()).andReturn(creds).anyTimes();
    PowerMock.mockStatic(ExternalCompactionUtil.class);
    List<RunningCompaction> runningCompactions = new ArrayList<>();
    EasyMock.expect(ExternalCompactionUtil.getCompactionsRunningOnCompactors(context)).andReturn(runningCompactions);
    CompactionFinalizer finalizer = PowerMock.createNiceMock(CompactionFinalizer.class);
    LiveTServerSet tservers = PowerMock.createNiceMock(LiveTServerSet.class);
    TServerInstance instance = PowerMock.createNiceMock(TServerInstance.class);
    EasyMock.expect(tservers.getCurrentServers()).andReturn(Collections.singleton(instance)).once();
    HostAndPort tserverAddress = HostAndPort.fromString("localhost:9997");
    EasyMock.expect(instance.getHostAndPort()).andReturn(tserverAddress).anyTimes();
    ServerAddress client = PowerMock.createNiceMock(ServerAddress.class);
    HostAndPort address = HostAndPort.fromString("localhost:10240");
    EasyMock.expect(client.getAddress()).andReturn(address).anyTimes();
    TServerInstance tsi = PowerMock.createNiceMock(TServerInstance.class);
    EasyMock.expect(tsi.getHostPort()).andReturn("localhost:9997").anyTimes();
    TabletClientService.Client tsc = PowerMock.createNiceMock(TabletClientService.Client.class);
    TCompactionQueueSummary queueSummary = PowerMock.createNiceMock(TCompactionQueueSummary.class);
    EasyMock.expect(tsc.getCompactionQueueInfo(EasyMock.anyObject(), EasyMock.anyObject())).andReturn(Collections.singletonList(queueSummary)).anyTimes();
    EasyMock.expect(queueSummary.getQueue()).andReturn("R2DQ").anyTimes();
    EasyMock.expect(queueSummary.getPriority()).andReturn((short) 1).anyTimes();
    ExternalCompactionId eci = ExternalCompactionId.generate(UUID.randomUUID());
    TExternalCompactionJob job = PowerMock.createNiceMock(TExternalCompactionJob.class);
    EasyMock.expect(job.getExternalCompactionId()).andReturn(eci.toString()).anyTimes();
    TInfo trace = TraceUtil.traceInfo();
    EasyMock.expect(tsc.reserveCompactionJob(trace, creds, "R2DQ", 1, "localhost:10241", eci.toString())).andReturn(job).anyTimes();
    AuditedSecurityOperation security = PowerMock.createNiceMock(AuditedSecurityOperation.class);
    EasyMock.expect(security.canPerformSystemActions(creds)).andReturn(true);
    PowerMock.replayAll();
    TestCoordinator coordinator = new TestCoordinator(conf, finalizer, tservers, client, tsc, context, security);
    coordinator.resetInternals();
    assertEquals(0, coordinator.getQueues().size());
    assertEquals(0, coordinator.getIndex().size());
    assertEquals(0, coordinator.getRunning().size());
    // Use coordinator.run() to populate the internal data structures. This is tested in a different
    // test.
    coordinator.run();
    assertEquals(1, coordinator.getQueues().size());
    QueueAndPriority qp = QueueAndPriority.get("R2DQ".intern(), (short) 1);
    Map<Short, TreeSet<TServerInstance>> m = coordinator.getQueues().get("R2DQ".intern());
    assertNotNull(m);
    assertEquals(1, m.size());
    assertTrue(m.containsKey((short) 1));
    Set<TServerInstance> t = m.get((short) 1);
    assertNotNull(t);
    assertEquals(1, t.size());
    TServerInstance queuedTsi = t.iterator().next();
    assertEquals(tsi.getHostPortSession(), queuedTsi.getHostPortSession());
    assertEquals(1, coordinator.getIndex().size());
    assertTrue(coordinator.getIndex().containsKey(queuedTsi));
    Set<QueueAndPriority> i = coordinator.getIndex().get(queuedTsi);
    assertEquals(1, i.size());
    assertEquals(qp, i.iterator().next());
    assertEquals(0, coordinator.getRunning().size());
    // Get the next job
    TExternalCompactionJob createdJob = coordinator.getCompactionJob(trace, creds, "R2DQ", "localhost:10241", eci.toString());
    assertEquals(eci.toString(), createdJob.getExternalCompactionId());
    assertEquals(1, coordinator.getQueues().size());
    assertEquals(1, coordinator.getIndex().size());
    assertEquals(1, coordinator.getRunning().size());
    Entry<ExternalCompactionId, RunningCompaction> entry = coordinator.getRunning().entrySet().iterator().next();
    assertEquals(eci.toString(), entry.getKey().toString());
    assertEquals("localhost:10241", entry.getValue().getCompactorAddress());
    assertEquals(eci.toString(), entry.getValue().getJob().getExternalCompactionId());
    PowerMock.verifyAll();
    coordinator.resetInternals();
    coordinator.close();
}
Also used : ExternalCompactionId(org.apache.accumulo.core.metadata.schema.ExternalCompactionId) ThriftUtil(org.apache.accumulo.core.rpc.ThriftUtil) ArrayList(java.util.ArrayList) ServerAddress(org.apache.accumulo.server.rpc.ServerAddress) AuditedSecurityOperation(org.apache.accumulo.server.security.AuditedSecurityOperation) TCompactionQueueSummary(org.apache.accumulo.core.tabletserver.thrift.TCompactionQueueSummary) LiveTServerSet(org.apache.accumulo.server.manager.LiveTServerSet) HostAndPort(org.apache.accumulo.core.util.HostAndPort) Client(org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Client) TreeSet(java.util.TreeSet) TExternalCompactionJob(org.apache.accumulo.core.tabletserver.thrift.TExternalCompactionJob) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) TInfo(org.apache.accumulo.core.trace.thrift.TInfo) TCredentials(org.apache.accumulo.core.securityImpl.thrift.TCredentials) RunningCompaction(org.apache.accumulo.core.util.compaction.RunningCompaction) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) AbstractServer(org.apache.accumulo.server.AbstractServer) ServerContext(org.apache.accumulo.server.ServerContext) TabletClientService(org.apache.accumulo.core.tabletserver.thrift.TabletClientService) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

ExternalCompactionId (org.apache.accumulo.core.metadata.schema.ExternalCompactionId)22 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)9 AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)8 TableId (org.apache.accumulo.core.data.TableId)8 TExternalCompactionList (org.apache.accumulo.core.compaction.thrift.TExternalCompactionList)6 TExternalCompactionJob (org.apache.accumulo.core.tabletserver.thrift.TExternalCompactionJob)6 ServerContext (org.apache.accumulo.server.ServerContext)6 HashSet (java.util.HashSet)4 TExternalCompaction (org.apache.accumulo.core.compaction.thrift.TExternalCompaction)4 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)4 TabletsMetadata (org.apache.accumulo.core.metadata.schema.TabletsMetadata)4 HostAndPort (org.apache.accumulo.core.util.HostAndPort)4 AbstractServer (org.apache.accumulo.server.AbstractServer)4 ServerAddress (org.apache.accumulo.server.rpc.ServerAddress)4 Text (org.apache.hadoop.io.Text)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 IOException (java.io.IOException)3 Collections (java.util.Collections)3 Set (java.util.Set)3