use of org.apache.accumulo.server.master.state.TServerInstance in project accumulo by apache.
the class MasterReplicationCoordinatorTest method invalidOffset.
@Test(expected = IllegalArgumentException.class)
public void invalidOffset() {
Master master = EasyMock.createMock(Master.class);
ZooReader reader = EasyMock.createMock(ZooReader.class);
Instance inst = EasyMock.createMock(Instance.class);
EasyMock.expect(master.getInstance()).andReturn(inst);
EasyMock.expect(inst.getInstanceID()).andReturn("1234");
EasyMock.replay(master, reader, inst);
MasterReplicationCoordinator coordinator = new MasterReplicationCoordinator(master, reader);
TServerInstance inst1 = new TServerInstance(HostAndPort.fromParts("host1", 1234), "session");
Assert.assertEquals(inst1, coordinator.getRandomTServer(Collections.singleton(inst1), 1));
}
use of org.apache.accumulo.server.master.state.TServerInstance in project accumulo by apache.
the class MasterReplicationCoordinatorTest method randomServerFromMany.
@Test
public void randomServerFromMany() {
Master master = EasyMock.createMock(Master.class);
ZooReader reader = EasyMock.createMock(ZooReader.class);
Instance inst = EasyMock.createMock(Instance.class);
EasyMock.expect(master.getInstance()).andReturn(inst).anyTimes();
EasyMock.expect(inst.getInstanceID()).andReturn("1234").anyTimes();
EasyMock.replay(master, reader, inst);
MasterReplicationCoordinator coordinator = new MasterReplicationCoordinator(master, reader);
EasyMock.verify(master, reader, inst);
TreeSet<TServerInstance> instances = new TreeSet<>();
TServerInstance inst1 = new TServerInstance(HostAndPort.fromParts("host1", 1234), "session");
instances.add(inst1);
TServerInstance inst2 = new TServerInstance(HostAndPort.fromParts("host2", 1234), "session");
instances.add(inst2);
Assert.assertEquals(inst1, coordinator.getRandomTServer(instances, 0));
Assert.assertEquals(inst2, coordinator.getRandomTServer(instances, 1));
}
use of org.apache.accumulo.server.master.state.TServerInstance in project accumulo by apache.
the class MasterReplicationCoordinatorTest method randomServer.
@Test
public void randomServer() {
Master master = EasyMock.createMock(Master.class);
ZooReader reader = EasyMock.createMock(ZooReader.class);
Instance inst = EasyMock.createMock(Instance.class);
EasyMock.expect(master.getInstance()).andReturn(inst);
EasyMock.expect(inst.getInstanceID()).andReturn("1234");
EasyMock.replay(master, reader, inst);
MasterReplicationCoordinator coordinator = new MasterReplicationCoordinator(master, reader);
TServerInstance inst1 = new TServerInstance(HostAndPort.fromParts("host1", 1234), "session");
Assert.assertEquals(inst1, coordinator.getRandomTServer(Collections.singleton(inst1), 0));
}
use of org.apache.accumulo.server.master.state.TServerInstance in project accumulo by apache.
the class CompactionDriver method isReady.
@Override
public long isReady(long tid, Master master) throws Exception {
String zCancelID = Constants.ZROOT + "/" + master.getInstance().getInstanceID() + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_COMPACT_CANCEL_ID;
IZooReaderWriter zoo = ZooReaderWriter.getInstance();
if (Long.parseLong(new String(zoo.getData(zCancelID, null))) >= compactId) {
// compaction was canceled
throw new AcceptableThriftTableOperationException(tableId.canonicalID(), null, TableOperation.COMPACT, TableOperationExceptionType.OTHER, "Compaction canceled");
}
MapCounter<TServerInstance> serversToFlush = new MapCounter<>();
Connector conn = master.getConnector();
Scanner scanner;
if (tableId.equals(MetadataTable.ID)) {
scanner = new IsolatedScanner(conn.createScanner(RootTable.NAME, Authorizations.EMPTY));
scanner.setRange(MetadataSchema.TabletsSection.getRange());
} else {
scanner = new IsolatedScanner(conn.createScanner(MetadataTable.NAME, Authorizations.EMPTY));
Range range = new KeyExtent(tableId, null, startRow == null ? null : new Text(startRow)).toMetadataRange();
scanner.setRange(range);
}
TabletsSection.ServerColumnFamily.COMPACT_COLUMN.fetch(scanner);
TabletsSection.ServerColumnFamily.DIRECTORY_COLUMN.fetch(scanner);
scanner.fetchColumnFamily(TabletsSection.CurrentLocationColumnFamily.NAME);
long t1 = System.currentTimeMillis();
RowIterator ri = new RowIterator(scanner);
int tabletsToWaitFor = 0;
int tabletCount = 0;
while (ri.hasNext()) {
Iterator<Entry<Key, Value>> row = ri.next();
long tabletCompactID = -1;
TServerInstance server = null;
Entry<Key, Value> entry = null;
while (row.hasNext()) {
entry = row.next();
Key key = entry.getKey();
if (TabletsSection.ServerColumnFamily.COMPACT_COLUMN.equals(key.getColumnFamily(), key.getColumnQualifier()))
tabletCompactID = Long.parseLong(entry.getValue().toString());
if (TabletsSection.CurrentLocationColumnFamily.NAME.equals(key.getColumnFamily()))
server = new TServerInstance(entry.getValue(), key.getColumnQualifier());
}
if (tabletCompactID < compactId) {
tabletsToWaitFor++;
if (server != null)
serversToFlush.increment(server, 1);
}
tabletCount++;
Text tabletEndRow = new KeyExtent(entry.getKey().getRow(), (Text) null).getEndRow();
if (tabletEndRow == null || (endRow != null && tabletEndRow.compareTo(new Text(endRow)) >= 0))
break;
}
long scanTime = System.currentTimeMillis() - t1;
Instance instance = master.getInstance();
Tables.clearCache(instance);
if (tabletCount == 0 && !Tables.exists(instance, tableId))
throw new AcceptableThriftTableOperationException(tableId.canonicalID(), null, TableOperation.COMPACT, TableOperationExceptionType.NOTFOUND, null);
if (serversToFlush.size() == 0 && Tables.getTableState(instance, tableId) == TableState.OFFLINE)
throw new AcceptableThriftTableOperationException(tableId.canonicalID(), null, TableOperation.COMPACT, TableOperationExceptionType.OFFLINE, null);
if (tabletsToWaitFor == 0)
return 0;
for (TServerInstance tsi : serversToFlush.keySet()) {
try {
final TServerConnection server = master.getConnection(tsi);
if (server != null)
server.compact(master.getMasterLock(), tableId.canonicalID(), startRow, endRow);
} catch (TException ex) {
LoggerFactory.getLogger(CompactionDriver.class).error(ex.toString());
}
}
long sleepTime = 500;
if (serversToFlush.size() > 0)
// make wait time depend on the server with the most to
sleepTime = Collections.max(serversToFlush.values()) * sleepTime;
// compact
sleepTime = Math.max(2 * scanTime, sleepTime);
sleepTime = Math.min(sleepTime, 30000);
return sleepTime;
}
use of org.apache.accumulo.server.master.state.TServerInstance in project accumulo by apache.
the class TabletServer method markUnusedWALs.
private void markUnusedWALs() {
Set<DfsLogger> candidates;
synchronized (closedLogs) {
candidates = new HashSet<>(closedLogs);
}
for (Tablet tablet : getOnlineTablets()) {
candidates.removeAll(tablet.getCurrentLogFiles());
}
try {
TServerInstance session = this.getTabletSession();
for (DfsLogger candidate : candidates) {
log.info("Marking " + candidate.getPath() + " as unreferenced");
walMarker.walUnreferenced(session, candidate.getPath());
}
synchronized (closedLogs) {
closedLogs.removeAll(candidates);
}
} catch (WalMarkerException ex) {
log.info(ex.toString(), ex);
}
}
Aggregations