Search in sources :

Example 76 with OMMetadataManager

use of org.apache.hadoop.ozone.om.OMMetadataManager in project ozone by apache.

the class TestOzoneFileInterfaces method testDirectory.

@Test
public void testDirectory() throws IOException {
    String leafName = RandomStringUtils.randomAlphanumeric(5);
    OMMetadataManager metadataManager = cluster.getOzoneManager().getMetadataManager();
    String lev1dir = "abc";
    Path lev1path = createPath("/" + lev1dir);
    String lev1key = metadataManager.getOzoneDirKey(volumeName, bucketName, o3fs.pathToKey(lev1path));
    String lev2dir = "def";
    Path lev2path = createPath("/" + lev1dir + "/" + lev2dir);
    String lev2key = metadataManager.getOzoneDirKey(volumeName, bucketName, o3fs.pathToKey(lev2path));
    FileStatus rootChild;
    FileStatus rootstatus;
    FileStatus leafstatus;
    Path leaf = createPath("/" + lev1dir + "/" + lev2dir + "/" + leafName);
    String leafKey = metadataManager.getOzoneDirKey(volumeName, bucketName, o3fs.pathToKey(leaf));
    // verify prefix directories and the leaf, do not already exist
    assertTrue(metadataManager.getKeyTable(getBucketLayout()).get(lev1key) == null);
    assertTrue(metadataManager.getKeyTable(getBucketLayout()).get(lev2key) == null);
    assertTrue(metadataManager.getKeyTable(getBucketLayout()).get(leafKey) == null);
    assertTrue("Makedirs returned with false for the path " + leaf, fs.mkdirs(leaf));
    // verify the leaf directory got created.
    leafstatus = getDirectoryStat(leaf);
    assertTrue(leafstatus != null);
    FileStatus lev1status;
    FileStatus lev2status;
    // verify prefix directories got created when creating the leaf directory.
    assertTrue(metadataManager.getKeyTable(getBucketLayout()).get(lev1key).getKeyName().equals("abc/"));
    assertTrue(metadataManager.getKeyTable(getBucketLayout()).get(lev2key).getKeyName().equals("abc/def/"));
    lev1status = getDirectoryStat(lev1path);
    lev2status = getDirectoryStat(lev2path);
    assertTrue((lev1status != null) && (lev2status != null));
    rootChild = lev1status;
    // check the root directory
    rootstatus = getDirectoryStat(createPath("/"));
    assertTrue(rootstatus != null);
    // root directory listing should contain the lev1 prefix directory
    FileStatus[] statusList = fs.listStatus(createPath("/"));
    assertEquals(1, statusList.length);
    assertEquals(rootChild, statusList[0]);
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) OzoneFileStatus(org.apache.hadoop.ozone.om.helpers.OzoneFileStatus) LocatedFileStatus(org.apache.hadoop.fs.LocatedFileStatus) OMMetadataManager(org.apache.hadoop.ozone.om.OMMetadataManager) Test(org.junit.Test)

Example 77 with OMMetadataManager

use of org.apache.hadoop.ozone.om.OMMetadataManager in project ozone by apache.

the class OMVolumeSetQuotaRequest method validateAndUpdateCache.

@Override
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, long transactionLogIndex, OzoneManagerDoubleBufferHelper ozoneManagerDoubleBufferHelper) {
    SetVolumePropertyRequest setVolumePropertyRequest = getOmRequest().getSetVolumePropertyRequest();
    Preconditions.checkNotNull(setVolumePropertyRequest);
    OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(getOmRequest());
    // when we have quota in bytes is set in setVolumePropertyRequest.
    if (!setVolumePropertyRequest.hasQuotaInBytes()) {
        omResponse.setStatus(OzoneManagerProtocolProtos.Status.INVALID_REQUEST).setSuccess(false);
        return new OMVolumeSetQuotaResponse(omResponse.build());
    }
    String volume = setVolumePropertyRequest.getVolumeName();
    OMMetrics omMetrics = ozoneManager.getMetrics();
    omMetrics.incNumVolumeUpdates();
    AuditLogger auditLogger = ozoneManager.getAuditLogger();
    OzoneManagerProtocolProtos.UserInfo userInfo = getOmRequest().getUserInfo();
    Map<String, String> auditMap = buildVolumeAuditMap(volume);
    auditMap.put(OzoneConsts.QUOTA_IN_BYTES, String.valueOf(setVolumePropertyRequest.getQuotaInBytes()));
    OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
    IOException exception = null;
    boolean acquireVolumeLock = false;
    OMClientResponse omClientResponse = null;
    try {
        // check Acl
        if (ozoneManager.getAclsEnabled()) {
            checkAcls(ozoneManager, OzoneObj.ResourceType.VOLUME, OzoneObj.StoreType.OZONE, IAccessAuthorizer.ACLType.WRITE, volume, null, null);
        }
        acquireVolumeLock = omMetadataManager.getLock().acquireWriteLock(VOLUME_LOCK, volume);
        OmVolumeArgs omVolumeArgs = getVolumeInfo(omMetadataManager, volume);
        if (checkQuotaBytesValid(omMetadataManager, setVolumePropertyRequest.getQuotaInBytes(), volume)) {
            omVolumeArgs.setQuotaInBytes(setVolumePropertyRequest.getQuotaInBytes());
        } else {
            omVolumeArgs.setQuotaInBytes(omVolumeArgs.getQuotaInBytes());
        }
        if (checkQuotaNamespaceValid(setVolumePropertyRequest.getQuotaInNamespace())) {
            omVolumeArgs.setQuotaInNamespace(setVolumePropertyRequest.getQuotaInNamespace());
        } else {
            omVolumeArgs.setQuotaInNamespace(omVolumeArgs.getQuotaInNamespace());
        }
        omVolumeArgs.setUpdateID(transactionLogIndex, ozoneManager.isRatisEnabled());
        omVolumeArgs.setModificationTime(setVolumePropertyRequest.getModificationTime());
        // update cache.
        omMetadataManager.getVolumeTable().addCacheEntry(new CacheKey<>(omMetadataManager.getVolumeKey(volume)), new CacheValue<>(Optional.of(omVolumeArgs), transactionLogIndex));
        omResponse.setSetVolumePropertyResponse(SetVolumePropertyResponse.newBuilder().build());
        omClientResponse = new OMVolumeSetQuotaResponse(omResponse.build(), omVolumeArgs);
    } catch (IOException ex) {
        exception = ex;
        omClientResponse = new OMVolumeSetQuotaResponse(createErrorOMResponse(omResponse, exception));
    } finally {
        addResponseToDoubleBuffer(transactionLogIndex, omClientResponse, ozoneManagerDoubleBufferHelper);
        if (acquireVolumeLock) {
            omMetadataManager.getLock().releaseWriteLock(VOLUME_LOCK, volume);
        }
    }
    // Performing audit logging outside of the lock.
    auditLog(auditLogger, buildAuditMessage(OMAction.SET_QUOTA, auditMap, exception, userInfo));
    // return response after releasing lock.
    if (exception == null) {
        LOG.debug("Changing volume quota is successfully completed for volume: " + "{} quota:{}", volume, setVolumePropertyRequest.getQuotaInBytes());
    } else {
        omMetrics.incNumVolumeUpdateFails();
        LOG.error("Changing volume quota failed for volume:{} quota:{}", volume, setVolumePropertyRequest.getQuotaInBytes(), exception);
    }
    return omClientResponse;
}
Also used : AuditLogger(org.apache.hadoop.ozone.audit.AuditLogger) OMClientResponse(org.apache.hadoop.ozone.om.response.OMClientResponse) OmVolumeArgs(org.apache.hadoop.ozone.om.helpers.OmVolumeArgs) IOException(java.io.IOException) OMResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse) OMMetrics(org.apache.hadoop.ozone.om.OMMetrics) OMVolumeSetQuotaResponse(org.apache.hadoop.ozone.om.response.volume.OMVolumeSetQuotaResponse) SetVolumePropertyRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.SetVolumePropertyRequest) OzoneManagerProtocolProtos(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos) OMMetadataManager(org.apache.hadoop.ozone.om.OMMetadataManager)

Example 78 with OMMetadataManager

use of org.apache.hadoop.ozone.om.OMMetadataManager in project ozone by apache.

the class OMVolumeSetOwnerRequest method validateAndUpdateCache.

@Override
public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, long transactionLogIndex, OzoneManagerDoubleBufferHelper ozoneManagerDoubleBufferHelper) {
    SetVolumePropertyRequest setVolumePropertyRequest = getOmRequest().getSetVolumePropertyRequest();
    Preconditions.checkNotNull(setVolumePropertyRequest);
    OMResponse.Builder omResponse = OmResponseUtil.getOMResponseBuilder(getOmRequest());
    // when we have ownerName in setVolumePropertyRequest.
    if (!setVolumePropertyRequest.hasOwnerName()) {
        omResponse.setStatus(OzoneManagerProtocolProtos.Status.INVALID_REQUEST).setSuccess(false);
        return new OMVolumeSetOwnerResponse(omResponse.build());
    }
    OMMetrics omMetrics = ozoneManager.getMetrics();
    omMetrics.incNumVolumeUpdates();
    String volume = setVolumePropertyRequest.getVolumeName();
    String newOwner = setVolumePropertyRequest.getOwnerName();
    AuditLogger auditLogger = ozoneManager.getAuditLogger();
    OzoneManagerProtocolProtos.UserInfo userInfo = getOmRequest().getUserInfo();
    Map<String, String> auditMap = buildVolumeAuditMap(volume);
    auditMap.put(OzoneConsts.OWNER, newOwner);
    boolean acquiredUserLocks = false;
    boolean acquiredVolumeLock = false;
    IOException exception = null;
    OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
    String oldOwner = null;
    OMClientResponse omClientResponse = null;
    try {
        // check Acl
        if (ozoneManager.getAclsEnabled()) {
            checkAcls(ozoneManager, OzoneObj.ResourceType.VOLUME, OzoneObj.StoreType.OZONE, IAccessAuthorizer.ACLType.WRITE_ACL, volume, null, null);
        }
        long maxUserVolumeCount = ozoneManager.getMaxUserVolumeCount();
        OzoneManagerStorageProtos.PersistedUserVolumeInfo oldOwnerVolumeList;
        OzoneManagerStorageProtos.PersistedUserVolumeInfo newOwnerVolumeList;
        OmVolumeArgs omVolumeArgs = null;
        acquiredVolumeLock = omMetadataManager.getLock().acquireWriteLock(VOLUME_LOCK, volume);
        omVolumeArgs = getVolumeInfo(omMetadataManager, volume);
        oldOwner = omVolumeArgs.getOwnerName();
        // Return OK immediately if newOwner is the same as oldOwner.
        if (oldOwner.equals(newOwner)) {
            LOG.warn("Volume '{}' owner is already user '{}'.", volume, oldOwner);
            omResponse.setStatus(OzoneManagerProtocolProtos.Status.OK).setMessage("Volume '" + volume + "' owner is already '" + newOwner + "'.").setSuccess(false);
            omResponse.setSetVolumePropertyResponse(SetVolumePropertyResponse.newBuilder().setResponse(false).build());
            omClientResponse = new OMVolumeSetOwnerResponse(omResponse.build());
            // Note: addResponseToDoubleBuffer would be executed in finally block.
            return omClientResponse;
        }
        acquiredUserLocks = omMetadataManager.getLock().acquireMultiUserLock(newOwner, oldOwner);
        oldOwnerVolumeList = omMetadataManager.getUserTable().get(oldOwner);
        oldOwnerVolumeList = delVolumeFromOwnerList(oldOwnerVolumeList, volume, oldOwner, transactionLogIndex);
        newOwnerVolumeList = omMetadataManager.getUserTable().get(newOwner);
        newOwnerVolumeList = addVolumeToOwnerList(newOwnerVolumeList, volume, newOwner, maxUserVolumeCount, transactionLogIndex);
        // Set owner with new owner name.
        omVolumeArgs.setOwnerName(newOwner);
        omVolumeArgs.setUpdateID(transactionLogIndex, ozoneManager.isRatisEnabled());
        // Update modificationTime.
        omVolumeArgs.setModificationTime(setVolumePropertyRequest.getModificationTime());
        // Update cache.
        omMetadataManager.getUserTable().addCacheEntry(new CacheKey<>(omMetadataManager.getUserKey(newOwner)), new CacheValue<>(Optional.of(newOwnerVolumeList), transactionLogIndex));
        omMetadataManager.getUserTable().addCacheEntry(new CacheKey<>(omMetadataManager.getUserKey(oldOwner)), new CacheValue<>(Optional.of(oldOwnerVolumeList), transactionLogIndex));
        omMetadataManager.getVolumeTable().addCacheEntry(new CacheKey<>(omMetadataManager.getVolumeKey(volume)), new CacheValue<>(Optional.of(omVolumeArgs), transactionLogIndex));
        omResponse.setSetVolumePropertyResponse(SetVolumePropertyResponse.newBuilder().setResponse(true).build());
        omClientResponse = new OMVolumeSetOwnerResponse(omResponse.build(), oldOwner, oldOwnerVolumeList, newOwnerVolumeList, omVolumeArgs);
    } catch (IOException ex) {
        exception = ex;
        omClientResponse = new OMVolumeSetOwnerResponse(createErrorOMResponse(omResponse, exception));
    } finally {
        addResponseToDoubleBuffer(transactionLogIndex, omClientResponse, ozoneManagerDoubleBufferHelper);
        if (acquiredUserLocks) {
            omMetadataManager.getLock().releaseMultiUserLock(newOwner, oldOwner);
        }
        if (acquiredVolumeLock) {
            omMetadataManager.getLock().releaseWriteLock(VOLUME_LOCK, volume);
        }
    }
    // Performing audit logging outside of the lock.
    auditLog(auditLogger, buildAuditMessage(OMAction.SET_OWNER, auditMap, exception, userInfo));
    // return response after releasing lock.
    if (exception == null) {
        LOG.debug("Successfully changed Owner of Volume {} from {} -> {}", volume, oldOwner, newOwner);
    } else {
        LOG.error("Changing volume ownership failed for user:{} volume:{}", newOwner, volume, exception);
        omMetrics.incNumVolumeUpdateFails();
    }
    return omClientResponse;
}
Also used : OzoneManagerStorageProtos(org.apache.hadoop.ozone.storage.proto.OzoneManagerStorageProtos) AuditLogger(org.apache.hadoop.ozone.audit.AuditLogger) OMClientResponse(org.apache.hadoop.ozone.om.response.OMClientResponse) OmVolumeArgs(org.apache.hadoop.ozone.om.helpers.OmVolumeArgs) IOException(java.io.IOException) OMResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse) OMMetrics(org.apache.hadoop.ozone.om.OMMetrics) SetVolumePropertyRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.SetVolumePropertyRequest) OzoneManagerProtocolProtos(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos) OMMetadataManager(org.apache.hadoop.ozone.om.OMMetadataManager) OMVolumeSetOwnerResponse(org.apache.hadoop.ozone.om.response.volume.OMVolumeSetOwnerResponse)

Example 79 with OMMetadataManager

use of org.apache.hadoop.ozone.om.OMMetadataManager in project ozone by apache.

the class TestOzoneManagerStateMachine method setup.

@Before
public void setup() throws Exception {
    OzoneManagerRatisServer ozoneManagerRatisServer = Mockito.mock(OzoneManagerRatisServer.class);
    OzoneManager ozoneManager = Mockito.mock(OzoneManager.class);
    // Allow testing of prepare pre-append gate.
    when(ozoneManager.isAdmin(any(String.class))).thenReturn(true);
    when(ozoneManager.isAdmin(any(UserGroupInformation.class))).thenReturn(true);
    OzoneConfiguration conf = new OzoneConfiguration();
    conf.set(OMConfigKeys.OZONE_OM_DB_DIRS, tempDir.newFolder().getAbsolutePath().toString());
    OMMetadataManager omMetadataManager = new OmMetadataManagerImpl(conf);
    when(ozoneManager.getMetadataManager()).thenReturn(omMetadataManager);
    prepareState = new OzoneManagerPrepareState(conf);
    when(ozoneManager.getPrepareState()).thenReturn(prepareState);
    when(ozoneManagerRatisServer.getOzoneManager()).thenReturn(ozoneManager);
    when(ozoneManager.getSnapshotInfo()).thenReturn(Mockito.mock(RatisSnapshotInfo.class));
    ozoneManagerStateMachine = new OzoneManagerStateMachine(ozoneManagerRatisServer, false);
    ozoneManagerStateMachine.notifyTermIndexUpdated(0, 0);
}
Also used : OmMetadataManagerImpl(org.apache.hadoop.ozone.om.OmMetadataManagerImpl) OzoneManager(org.apache.hadoop.ozone.om.OzoneManager) OMMetadataManager(org.apache.hadoop.ozone.om.OMMetadataManager) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) OzoneManagerPrepareState(org.apache.hadoop.ozone.om.OzoneManagerPrepareState) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) RatisSnapshotInfo(org.apache.hadoop.ozone.common.ha.ratis.RatisSnapshotInfo) Before(org.junit.Before)

Aggregations

OMMetadataManager (org.apache.hadoop.ozone.om.OMMetadataManager)79 IOException (java.io.IOException)45 OMClientResponse (org.apache.hadoop.ozone.om.response.OMClientResponse)43 OMResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse)40 OmKeyInfo (org.apache.hadoop.ozone.om.helpers.OmKeyInfo)32 OmBucketInfo (org.apache.hadoop.ozone.om.helpers.OmBucketInfo)30 OMException (org.apache.hadoop.ozone.om.exceptions.OMException)29 OMMetrics (org.apache.hadoop.ozone.om.OMMetrics)26 Test (org.junit.Test)22 AuditLogger (org.apache.hadoop.ozone.audit.AuditLogger)19 OzoneManagerProtocolProtos (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos)19 ArrayList (java.util.ArrayList)17 KeyArgs (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.KeyArgs)17 OmVolumeArgs (org.apache.hadoop.ozone.om.helpers.OmVolumeArgs)13 ReconOMMetadataManager (org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager)12 OmKeyLocationInfo (org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo)11 OzoneConfiguration (org.apache.hadoop.hdds.conf.OzoneConfiguration)9 HashMap (java.util.HashMap)8 OmMetadataManagerImpl (org.apache.hadoop.ozone.om.OmMetadataManagerImpl)7 RepeatedOmKeyInfo (org.apache.hadoop.ozone.om.helpers.RepeatedOmKeyInfo)7