use of org.apache.asterix.metadata.entities.NodeGroup in project asterixdb by apache.
the class QueryTranslator method handleNodegroupDropStatement.
protected void handleNodegroupDropStatement(MetadataProvider metadataProvider, Statement stmt) throws Exception {
NodeGroupDropStatement stmtDelete = (NodeGroupDropStatement) stmt;
String nodegroupName = stmtDelete.getNodeGroupName().getValue();
MetadataTransactionContext mdTxnCtx = MetadataManager.INSTANCE.beginTransaction();
metadataProvider.setMetadataTxnContext(mdTxnCtx);
MetadataLockManager.INSTANCE.acquireNodeGroupWriteLock(metadataProvider.getLocks(), nodegroupName);
try {
NodeGroup ng = MetadataManager.INSTANCE.getNodegroup(mdTxnCtx, nodegroupName);
if (ng == null) {
if (!stmtDelete.getIfExists()) {
throw new AlgebricksException("There is no nodegroup with this name " + nodegroupName + ".");
}
} else {
MetadataManager.INSTANCE.dropNodegroup(mdTxnCtx, nodegroupName, false);
}
MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
} catch (Exception e) {
abort(e, e, mdTxnCtx);
throw e;
} finally {
metadataProvider.getLocks().unlock();
}
}
use of org.apache.asterix.metadata.entities.NodeGroup in project asterixdb by apache.
the class MetadataBootstrap method insertInitialGroups.
private static void insertInitialGroups(MetadataTransactionContext mdTxnCtx) throws MetadataException {
List<String> metadataGroupNodeNames = new ArrayList<>();
metadataGroupNodeNames.add(metadataNodeName);
NodeGroup groupRecord = new NodeGroup(MetadataConstants.METADATA_NODEGROUP_NAME, metadataGroupNodeNames);
MetadataManager.INSTANCE.addNodegroup(mdTxnCtx, groupRecord);
}
use of org.apache.asterix.metadata.entities.NodeGroup in project asterixdb by apache.
the class DatasetUtil method createNodeGroupForNewDataset.
/***
* Creates a node group that is associated with a new dataset.
*
* @param dataverseName,
* the dataverse name of the dataset.
* @param datasetName,
* the name of the dataset.
* @param rebalanceCount
* , the rebalance count of the dataset.
* @param ncNames,
* the set of node names.
* @param metadataProvider,
* the metadata provider.
* @return the name of the created node group.
* @throws Exception
*/
public static String createNodeGroupForNewDataset(String dataverseName, String datasetName, long rebalanceCount, Set<String> ncNames, MetadataProvider metadataProvider) throws Exception {
String nodeGroup = dataverseName + "." + datasetName + (rebalanceCount == 0L ? "" : "_" + rebalanceCount);
MetadataTransactionContext mdTxnCtx = metadataProvider.getMetadataTxnContext();
MetadataLockManager.INSTANCE.acquireNodeGroupWriteLock(metadataProvider.getLocks(), nodeGroup);
NodeGroup ng = MetadataManager.INSTANCE.getNodegroup(mdTxnCtx, nodeGroup);
if (ng != null) {
nodeGroup = nodeGroup + "_" + UUID.randomUUID().toString();
MetadataLockManager.INSTANCE.acquireNodeGroupWriteLock(metadataProvider.getLocks(), nodeGroup);
}
MetadataManager.INSTANCE.addNodegroup(mdTxnCtx, new NodeGroup(nodeGroup, new ArrayList<>(ncNames)));
return nodeGroup;
}
use of org.apache.asterix.metadata.entities.NodeGroup in project asterixdb by apache.
the class QueryTranslator method handleCreateNodeGroupStatement.
protected void handleCreateNodeGroupStatement(MetadataProvider metadataProvider, Statement stmt) throws Exception {
NodegroupDecl stmtCreateNodegroup = (NodegroupDecl) stmt;
String ngName = stmtCreateNodegroup.getNodegroupName().getValue();
MetadataTransactionContext mdTxnCtx = MetadataManager.INSTANCE.beginTransaction();
metadataProvider.setMetadataTxnContext(mdTxnCtx);
MetadataLockManager.INSTANCE.acquireNodeGroupWriteLock(metadataProvider.getLocks(), ngName);
try {
NodeGroup ng = MetadataManager.INSTANCE.getNodegroup(mdTxnCtx, ngName);
if (ng != null) {
if (!stmtCreateNodegroup.getIfNotExists()) {
throw new AlgebricksException("A nodegroup with this name " + ngName + " already exists.");
}
} else {
List<Identifier> ncIdentifiers = stmtCreateNodegroup.getNodeControllerNames();
List<String> ncNames = new ArrayList<>(ncIdentifiers.size());
for (Identifier id : ncIdentifiers) {
ncNames.add(id.getValue());
}
MetadataManager.INSTANCE.addNodegroup(mdTxnCtx, new NodeGroup(ngName, ncNames));
}
MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
} catch (Exception e) {
abort(e, e, mdTxnCtx);
throw e;
} finally {
metadataProvider.getLocks().unlock();
}
}
use of org.apache.asterix.metadata.entities.NodeGroup in project asterixdb by apache.
the class MetadataManager method getNodegroup.
@Override
public NodeGroup getNodegroup(MetadataTransactionContext ctx, String nodeGroupName) throws MetadataException {
// First look in the context to see if this transaction created the
// requested dataverse itself (but the dataverse is still uncommitted).
NodeGroup nodeGroup = ctx.getNodeGroup(nodeGroupName);
if (nodeGroup != null) {
// uncommitted.
return nodeGroup;
}
if (ctx.nodeGroupIsDropped(nodeGroupName)) {
// in the cache.
return null;
}
nodeGroup = cache.getNodeGroup(nodeGroupName);
if (nodeGroup != null) {
// NodeGroup is already in the cache, don't add it again.
return nodeGroup;
}
try {
nodeGroup = metadataNode.getNodeGroup(ctx.getJobId(), nodeGroupName);
} catch (RemoteException e) {
throw new MetadataException(e);
}
// when this transaction commits.
if (nodeGroup != null) {
ctx.addNodeGroup(nodeGroup);
}
return nodeGroup;
}
Aggregations