Search in sources :

Example 1 with NodeGroup

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();
    }
}
Also used : AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) MetadataTransactionContext(org.apache.asterix.metadata.MetadataTransactionContext) NodeGroupDropStatement(org.apache.asterix.lang.common.statement.NodeGroupDropStatement) ACIDException(org.apache.asterix.common.exceptions.ACIDException) MetadataException(org.apache.asterix.metadata.MetadataException) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) CompilationException(org.apache.asterix.common.exceptions.CompilationException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) AsterixException(org.apache.asterix.common.exceptions.AsterixException) NodeGroup(org.apache.asterix.metadata.entities.NodeGroup)

Example 2 with NodeGroup

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);
}
Also used : ArrayList(java.util.ArrayList) NodeGroup(org.apache.asterix.metadata.entities.NodeGroup)

Example 3 with NodeGroup

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;
}
Also used : ArrayList(java.util.ArrayList) MetadataTransactionContext(org.apache.asterix.metadata.MetadataTransactionContext) AMutableString(org.apache.asterix.om.base.AMutableString) AString(org.apache.asterix.om.base.AString) NodeGroup(org.apache.asterix.metadata.entities.NodeGroup)

Example 4 with 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();
    }
}
Also used : NodegroupDecl(org.apache.asterix.lang.common.statement.NodegroupDecl) Identifier(org.apache.asterix.lang.common.struct.Identifier) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) ArrayList(java.util.ArrayList) MetadataTransactionContext(org.apache.asterix.metadata.MetadataTransactionContext) ACIDException(org.apache.asterix.common.exceptions.ACIDException) MetadataException(org.apache.asterix.metadata.MetadataException) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) CompilationException(org.apache.asterix.common.exceptions.CompilationException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) AsterixException(org.apache.asterix.common.exceptions.AsterixException) NodeGroup(org.apache.asterix.metadata.entities.NodeGroup)

Example 5 with NodeGroup

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;
}
Also used : RemoteException(java.rmi.RemoteException) NodeGroup(org.apache.asterix.metadata.entities.NodeGroup)

Aggregations

NodeGroup (org.apache.asterix.metadata.entities.NodeGroup)9 ArrayList (java.util.ArrayList)6 RemoteException (java.rmi.RemoteException)3 MetadataTransactionContext (org.apache.asterix.metadata.MetadataTransactionContext)3 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)3 IOException (java.io.IOException)2 ACIDException (org.apache.asterix.common.exceptions.ACIDException)2 AsterixException (org.apache.asterix.common.exceptions.AsterixException)2 CompilationException (org.apache.asterix.common.exceptions.CompilationException)2 MetadataException (org.apache.asterix.metadata.MetadataException)2 AString (org.apache.asterix.om.base.AString)2 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInput (java.io.DataInput)1 DataInputStream (java.io.DataInputStream)1 NodeGroupDropStatement (org.apache.asterix.lang.common.statement.NodeGroupDropStatement)1 NodegroupDecl (org.apache.asterix.lang.common.statement.NodegroupDecl)1 Identifier (org.apache.asterix.lang.common.struct.Identifier)1 NodeGroupTupleTranslator (org.apache.asterix.metadata.entitytupletranslators.NodeGroupTupleTranslator)1 MetadataEntityValueExtractor (org.apache.asterix.metadata.valueextractors.MetadataEntityValueExtractor)1