use of co.cask.cdap.api.data.DatasetContext in project cdap by caskdata.
the class DefaultStore method upgrade.
/**
* Method to add version in DefaultStore.
*
* @throws InterruptedException
* @throws IOException
* @throws DatasetManagementException
*/
public void upgrade() throws InterruptedException, IOException, DatasetManagementException {
// If upgrade is already complete, then simply return.
if (isUpgradeComplete()) {
LOG.info("{} is already upgraded.", NAME);
return;
}
final AtomicInteger maxRows = new AtomicInteger(1000);
final AtomicInteger sleepTimeInSecs = new AtomicInteger(60);
LOG.info("Starting upgrade of {}.", NAME);
// to check whether they need to do additional scans to accommodate old data formats.
while (!isUpgradeComplete()) {
sleepTimeInSecs.set(60);
try {
Transactions.execute(transactional, new TxCallable<Void>() {
@Override
public Void call(DatasetContext context) throws Exception {
AppMetadataStore store = getAppMetadataStore(context);
boolean upgradeComplete = store.upgradeVersionKeys(maxRows.get());
if (upgradeComplete) {
store.setUpgradeComplete(APP_VERSION_UPGRADE_KEY);
}
return null;
}
});
} catch (TransactionFailureException e) {
if (e instanceof TransactionConflictException) {
LOG.debug("Upgrade step faced Transaction Conflict exception. Retrying operation now.", e);
sleepTimeInSecs.set(10);
} else if (e instanceof TransactionNotInProgressException) {
int currMaxRows = maxRows.get();
if (currMaxRows > 500) {
maxRows.decrementAndGet();
} else {
LOG.warn("Could not complete upgrade of {}, tried for 500 times", NAME);
return;
}
sleepTimeInSecs.set(10);
LOG.debug("Upgrade step faced a Transaction Timeout exception. " + "Reducing the number of max rows to : {} and retrying the operation now.", maxRows.get(), e);
} else {
LOG.error("Upgrade step faced exception. Will retry operation after some delay.", e);
sleepTimeInSecs.set(60);
}
}
TimeUnit.SECONDS.sleep(sleepTimeInSecs.get());
}
LOG.info("Upgrade of {} is complete.", NAME);
}
use of co.cask.cdap.api.data.DatasetContext in project cdap by caskdata.
the class DefaultStore method removeAllApplications.
@Override
public void removeAllApplications(final NamespaceId id) {
LOG.trace("Removing all applications of namespace with id: {}", id.getNamespace());
Transactions.executeUnchecked(transactional, new TxRunnable() {
@Override
public void run(DatasetContext context) throws Exception {
AppMetadataStore metaStore = getAppMetadataStore(context);
metaStore.deleteApplications(id.getNamespace());
metaStore.deleteProgramHistory(id.getNamespace());
}
});
}
use of co.cask.cdap.api.data.DatasetContext in project cdap by caskdata.
the class DefaultStore method removeAll.
@Override
public void removeAll(final NamespaceId id) {
LOG.trace("Removing all applications of namespace with id: {}", id.getNamespace());
Transactions.executeUnchecked(transactional, new TxRunnable() {
@Override
public void run(DatasetContext context) throws Exception {
AppMetadataStore metaStore = getAppMetadataStore(context);
metaStore.deleteApplications(id.getNamespace());
metaStore.deleteAllStreams(id.getNamespace());
metaStore.deleteProgramHistory(id.getNamespace());
}
});
}
use of co.cask.cdap.api.data.DatasetContext in project cdap by caskdata.
the class DefaultStore method setServiceInstances.
@Override
public void setServiceInstances(final ProgramId id, final int instances) {
Preconditions.checkArgument(instances > 0, "Cannot change number of service instances to %s", instances);
Transactions.executeUnchecked(transactional, new TxRunnable() {
@Override
public void run(DatasetContext context) throws Exception {
AppMetadataStore metaStore = getAppMetadataStore(context);
ApplicationSpecification appSpec = getAppSpecOrFail(metaStore, id);
ServiceSpecification serviceSpec = getServiceSpecOrFail(id, appSpec);
// Create a new spec copy from the old one, except with updated instances number
serviceSpec = new ServiceSpecification(serviceSpec.getClassName(), serviceSpec.getName(), serviceSpec.getDescription(), serviceSpec.getHandlers(), serviceSpec.getResources(), instances);
ApplicationSpecification newAppSpec = replaceServiceSpec(appSpec, id.getProgram(), serviceSpec);
metaStore.updateAppSpec(id.getNamespace(), id.getApplication(), id.getVersion(), newAppSpec);
}
});
LOG.trace("Setting program instances: namespace: {}, application: {}, service: {}, new instances count: {}", id.getNamespaceId(), id.getApplication(), id.getProgram(), instances);
}
use of co.cask.cdap.api.data.DatasetContext in project cdap by caskdata.
the class DefaultStore method removeApplication.
@Override
public void removeApplication(final ApplicationId id) {
LOG.trace("Removing application: namespace: {}, application: {}", id.getNamespace(), id.getApplication());
Transactions.executeUnchecked(transactional, new TxRunnable() {
@Override
public void run(DatasetContext context) throws Exception {
AppMetadataStore metaStore = getAppMetadataStore(context);
metaStore.deleteApplication(id.getNamespace(), id.getApplication(), id.getVersion());
metaStore.deleteProgramHistory(id.getNamespace(), id.getApplication(), id.getVersion());
}
});
}
Aggregations