use of org.apache.accumulo.tserver.managermessage.TabletStatusMessage in project accumulo by apache.
the class UnloadTabletHandler method run.
@Override
public void run() {
Tablet t = null;
synchronized (server.unopenedTablets) {
if (server.unopenedTablets.contains(extent)) {
server.unopenedTablets.remove(extent);
// enqueueManagerMessage(new TabletUnloadedMessage(extent));
return;
}
}
synchronized (server.openingTablets) {
while (server.openingTablets.contains(extent)) {
try {
log.info("Waiting for tablet {} to finish opening before unloading.", extent);
server.openingTablets.wait();
} catch (InterruptedException e) {
}
}
}
synchronized (server.onlineTablets) {
if (server.onlineTablets.snapshot().containsKey(extent)) {
t = server.onlineTablets.snapshot().get(extent);
}
}
if (t == null) {
// unload request is crossing the successful unloaded message
if (!server.recentlyUnloadedCache.containsKey(extent)) {
log.info("told to unload tablet that was not being served {}", extent);
server.enqueueManagerMessage(new TabletStatusMessage(TabletLoadState.UNLOAD_FAILURE_NOT_SERVING, extent));
}
return;
}
try {
t.close(!goalState.equals(TUnloadTabletGoal.DELETED));
} catch (Exception e) {
if ((t.isClosing() || t.isClosed()) && e instanceof IllegalStateException) {
log.debug("Failed to unload tablet {}... it was already closing or closed : {}", extent, e.getMessage());
} else {
log.error("Failed to close tablet {}... Aborting migration", extent, e);
server.enqueueManagerMessage(new TabletStatusMessage(TabletLoadState.UNLOAD_ERROR, extent));
}
return;
}
// stop serving tablet - client will get not serving tablet
// exceptions
server.recentlyUnloadedCache.put(extent, System.currentTimeMillis());
server.onlineTablets.remove(extent);
try {
TServerInstance instance = new TServerInstance(server.clientAddress, server.getLock().getSessionId());
TabletLocationState tls = null;
try {
tls = new TabletLocationState(extent, null, instance, null, null, null, false);
} catch (BadLocationStateException e) {
log.error("Unexpected error", e);
}
if (!goalState.equals(TUnloadTabletGoal.SUSPENDED) || extent.isRootTablet() || (extent.isMeta() && !server.getConfiguration().getBoolean(Property.MANAGER_METADATA_SUSPENDABLE))) {
TabletStateStore.unassign(server.getContext(), tls, null);
} else {
TabletStateStore.suspend(server.getContext(), tls, null, requestTimeSkew + NANOSECONDS.toMillis(System.nanoTime()));
}
} catch (DistributedStoreException ex) {
log.warn("Unable to update storage", ex);
} catch (KeeperException e) {
log.warn("Unable determine our zookeeper session information", e);
} catch (InterruptedException e) {
log.warn("Interrupted while getting our zookeeper session information", e);
}
// tell the manager how it went
server.enqueueManagerMessage(new TabletStatusMessage(TabletLoadState.UNLOADED, extent));
// roll tablet stats over into tablet server's statsKeeper object as
// historical data
server.statsKeeper.saveMajorMinorTimes(t.getTabletStats());
}
use of org.apache.accumulo.tserver.managermessage.TabletStatusMessage in project accumulo by apache.
the class AssignmentHandler method run.
@Override
public void run() {
synchronized (server.unopenedTablets) {
synchronized (server.openingTablets) {
synchronized (server.onlineTablets) {
// nothing should be moving between sets, do a sanity
// check
Set<KeyExtent> unopenedOverlapping = KeyExtent.findOverlapping(extent, server.unopenedTablets);
Set<KeyExtent> openingOverlapping = KeyExtent.findOverlapping(extent, server.openingTablets);
Set<KeyExtent> onlineOverlapping = KeyExtent.findOverlapping(extent, server.onlineTablets.snapshot());
if (openingOverlapping.contains(extent) || onlineOverlapping.contains(extent)) {
return;
}
if (!unopenedOverlapping.contains(extent)) {
log.info("assignment {} no longer in the unopened set", extent);
return;
}
if (unopenedOverlapping.size() != 1 || !openingOverlapping.isEmpty() || !onlineOverlapping.isEmpty()) {
throw new IllegalStateException("overlaps assigned " + extent + " " + !server.unopenedTablets.contains(extent) + " " + unopenedOverlapping + " " + openingOverlapping + " " + onlineOverlapping);
}
}
server.unopenedTablets.remove(extent);
server.openingTablets.add(extent);
}
}
// check Metadata table before accepting assignment
Text locationToOpen = null;
TabletMetadata tabletMetadata = null;
boolean canLoad = false;
try {
tabletMetadata = server.getContext().getAmple().readTablet(extent);
canLoad = checkTabletMetadata(extent, server.getTabletSession(), tabletMetadata);
if (canLoad && tabletMetadata.sawOldPrevEndRow()) {
KeyExtent fixedExtent = ManagerMetadataUtil.fixSplit(server.getContext(), tabletMetadata, server.getLock());
synchronized (server.openingTablets) {
server.openingTablets.remove(extent);
server.openingTablets.notifyAll();
// should not be added to unopenedTablets
if (!KeyExtent.findOverlapping(extent, new TreeSet<>(Arrays.asList(fixedExtent))).contains(fixedExtent)) {
throw new IllegalStateException("Fixed split does not overlap " + extent + " " + fixedExtent);
}
server.unopenedTablets.add(fixedExtent);
}
// split was rolled back... try again
new AssignmentHandler(server, fixedExtent).run();
return;
}
} catch (Exception e) {
synchronized (server.openingTablets) {
server.openingTablets.remove(extent);
server.openingTablets.notifyAll();
}
log.warn("Failed to verify tablet " + extent, e);
server.enqueueManagerMessage(new TabletStatusMessage(TabletLoadState.LOAD_FAILURE, extent));
throw new RuntimeException(e);
}
if (!canLoad) {
log.debug("Reporting tablet {} assignment failure: unable to verify Tablet Information", extent);
synchronized (server.openingTablets) {
server.openingTablets.remove(extent);
server.openingTablets.notifyAll();
}
server.enqueueManagerMessage(new TabletStatusMessage(TabletLoadState.LOAD_FAILURE, extent));
return;
}
Tablet tablet = null;
boolean successful = false;
try {
server.acquireRecoveryMemory(extent);
TabletResourceManager trm = server.resourceManager.createTabletResourceManager(extent, server.getTableConfiguration(extent));
TabletData data = new TabletData(tabletMetadata);
tablet = new Tablet(server, extent, trm, data);
// this could cause duplicate data to replay.
if (tablet.getNumEntriesInMemory() > 0 && !tablet.minorCompactNow(MinorCompactionReason.RECOVERY)) {
throw new RuntimeException("Minor compaction after recovery fails for " + extent);
}
Assignment assignment = new Assignment(extent, server.getTabletSession());
TabletStateStore.setLocation(server.getContext(), assignment);
synchronized (server.openingTablets) {
synchronized (server.onlineTablets) {
server.openingTablets.remove(extent);
server.onlineTablets.put(extent, tablet);
server.openingTablets.notifyAll();
server.recentlyUnloadedCache.remove(tablet.getExtent());
}
}
// release this reference
tablet = null;
successful = true;
} catch (Exception e) {
log.warn("exception trying to assign tablet {} {}", extent, locationToOpen, e);
if (e.getMessage() != null) {
log.warn("{}", e.getMessage());
}
TableId tableId = extent.tableId();
ProblemReports.getInstance(server.getContext()).report(new ProblemReport(tableId, TABLET_LOAD, extent.getUUID().toString(), server.getClientAddressString(), e));
} finally {
server.releaseRecoveryMemory(extent);
}
if (successful) {
server.enqueueManagerMessage(new TabletStatusMessage(TabletLoadState.LOADED, extent));
} else {
synchronized (server.unopenedTablets) {
synchronized (server.openingTablets) {
server.openingTablets.remove(extent);
server.unopenedTablets.add(extent);
server.openingTablets.notifyAll();
}
}
log.warn("failed to open tablet {} reporting failure to manager", extent);
server.enqueueManagerMessage(new TabletStatusMessage(TabletLoadState.LOAD_FAILURE, extent));
long reschedule = Math.min((1L << Math.min(32, retryAttempt)) * 1000, MINUTES.toMillis(10));
log.warn(String.format("rescheduling tablet load in %.2f seconds", reschedule / 1000.));
this.server.getContext().getScheduledExecutor().schedule(new Runnable() {
@Override
public void run() {
log.info("adding tablet {} back to the assignment pool (retry {})", extent, retryAttempt);
AssignmentHandler handler = new AssignmentHandler(server, extent, retryAttempt + 1);
if (extent.isMeta()) {
if (extent.isRootTablet()) {
Threads.createThread("Root tablet assignment retry", handler).start();
} else {
server.resourceManager.addMetaDataAssignment(extent, log, handler);
}
} else {
server.resourceManager.addAssignment(extent, log, handler);
}
}
}, reschedule, TimeUnit.MILLISECONDS);
}
}
use of org.apache.accumulo.tserver.managermessage.TabletStatusMessage in project accumulo by apache.
the class CompactableImpl method markChopped.
private void markChopped() {
MetadataTableUtil.chopped(tablet.getTabletServer().getContext(), getExtent(), tablet.getTabletServer().getLock());
tablet.getTabletServer().enqueueManagerMessage(new TabletStatusMessage(TabletLoadState.CHOPPED, getExtent()));
}
Aggregations