@Test public void testCheckObjectAndGetSize() throws Exception { String volumeName = "testCheckObjectAndGetSize"; client.createVolume(mrcAddress, auth, userCredentials, volumeName); AdminVolume volume = client.openVolume(volumeName, null, options); volume.start(); AdminFileHandle fileHandle = volume.openFile( userCredentials, "/test.txt", SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber() | SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_RDWR.getNumber(), 0777); String content = ""; for (int i = 0; i < 6000; i++) content = content.concat("Hello World "); byte[] bytesIn = content.getBytes(); int length = bytesIn.length; fileHandle.write(userCredentials, bytesIn, length, 0); fileHandle.close(); int objSize = fileHandle.checkObjectAndGetSize(0, 0); assertEquals(length, objSize); HashStorageLayout hsl = new HashStorageLayout(testEnv.getOSDConfig(fileHandle.getReplica(0).getOsdUuids(0)), new MetadataCache()); String filePath = hsl.generateAbsoluteFilePath(fileHandle.getGlobalFileId()); File fileDir = new File(filePath); File[] fileList = fileDir.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return (!pathname.getName().startsWith(".")); } }); assertTrue(fileList.length > 0); FileWriter writer = new FileWriter(fileList[0], true); writer.write("foofoofoofoo"); writer.close(); try { fileHandle.checkObjectAndGetSize(0, 0); assertTrue(false); } catch (InvalidChecksumException e) { assertTrue(true); } volume.close(); client.deleteVolume(auth, userCredentials, volumeName); }
@Override public int checkObjectAndGetSize(int replicaIndex, long objectNo) throws IOException, InvalidChecksumException { ObjectData od = null; RPCResponse<ObjectData> osdRsp = null; try { FileCredentials.Builder fcBuilder = FileCredentials.newBuilder(); fcBuilder.setXlocs(fileInfo.getXLocSet()); fcBuilder.setXcap(getXcap()); String fileId = Helper.extractGlobalFileIdFromXcap(fcBuilder.getXcap()); Replica r = getReplica(replicaIndex); String objOsd = r.getOsdUuids((int) objectNo % r.getStripingPolicy().getWidth()); UUIDIterator it = new UUIDIterator(); it.addUUID(objOsd); xtreemfs_check_objectRequest request = xtreemfs_check_objectRequest.newBuilder() .setFileCredentials(fcBuilder.build()).setFileId(fileId).setObjectNumber(objectNo) .setObjectVersion(0l).build(); od = RPCCaller.<xtreemfs_check_objectRequest, ObjectData> syncCall(SERVICES.OSD, RPCAuthentication.userService, RPCAuthentication.authNone, volumeOptions, uuidResolver, it, false, request, new CallGenerator<xtreemfs_check_objectRequest, ObjectData>() { @Override public RPCResponse<ObjectData> executeCall(InetSocketAddress server, Auth authHeader, UserCredentials userCreds, xtreemfs_check_objectRequest input) throws IOException, PosixErrorException { return osdServiceClient.xtreemfs_check_object(server, authHeader, userCreds, input); } }); } catch (IOException e) { if (Logging.isDebug()) Logging.logMessage(Logging.LEVEL_DEBUG, this, "IO error: %s", e.toString()); throw new IOException("operation aborted", e); } if (od.getInvalidChecksumOnOsd()) { throw new InvalidChecksumException("object " + objectNo + " has an invalid checksum"); } return od.getZeroPadding(); }
FileHandleImplementation implements FileHandle, AdminFileHandle { @Override public int checkObjectAndGetSize(int replicaIndex, long objectNo) throws IOException, InvalidChecksumException { ObjectData od = null; RPCResponse<ObjectData> osdRsp = null; try { FileCredentials.Builder fcBuilder = FileCredentials.newBuilder(); fcBuilder.setXlocs(fileInfo.getXLocSet()); fcBuilder.setXcap(getXcap()); String fileId = Helper.extractGlobalFileIdFromXcap(fcBuilder.getXcap()); Replica r = getReplica(replicaIndex); String objOsd = r.getOsdUuids((int) objectNo % r.getStripingPolicy().getWidth()); UUIDIterator it = new UUIDIterator(); it.addUUID(objOsd); xtreemfs_check_objectRequest request = xtreemfs_check_objectRequest.newBuilder() .setFileCredentials(fcBuilder.build()).setFileId(fileId).setObjectNumber(objectNo) .setObjectVersion(0l).build(); od = RPCCaller.<xtreemfs_check_objectRequest, ObjectData> syncCall(SERVICES.OSD, RPCAuthentication.userService, RPCAuthentication.authNone, volumeOptions, uuidResolver, it, false, request, new CallGenerator<xtreemfs_check_objectRequest, ObjectData>() { @Override public RPCResponse<ObjectData> executeCall(InetSocketAddress server, Auth authHeader, UserCredentials userCreds, xtreemfs_check_objectRequest input) throws IOException, PosixErrorException { return osdServiceClient.xtreemfs_check_object(server, authHeader, userCreds, input); } }); } catch (IOException e) { if (Logging.isDebug()) Logging.logMessage(Logging.LEVEL_DEBUG, this, "IO error: %s", e.toString()); throw new IOException("operation aborted", e); } if (od.getInvalidChecksumOnOsd()) { throw new InvalidChecksumException("object " + objectNo + " has an invalid checksum"); } return od.getZeroPadding(); } }
FileHandleImplementation implements FileHandle, AdminFileHandle { @Override public int checkObjectAndGetSize(int replicaIndex, long objectNo) throws IOException, InvalidChecksumException { ObjectData od = null; RPCResponse<ObjectData> osdRsp = null; try { FileCredentials.Builder fcBuilder = FileCredentials.newBuilder(); fcBuilder.setXlocs(fileInfo.getXLocSet()); fcBuilder.setXcap(getXcap()); String fileId = Helper.extractGlobalFileIdFromXcap(fcBuilder.getXcap()); Replica r = getReplica(replicaIndex); String objOsd = r.getOsdUuids((int) objectNo % r.getStripingPolicy().getWidth()); UUIDIterator it = new UUIDIterator(); it.addUUID(objOsd); xtreemfs_check_objectRequest request = xtreemfs_check_objectRequest.newBuilder() .setFileCredentials(fcBuilder.build()).setFileId(fileId).setObjectNumber(objectNo) .setObjectVersion(0l).build(); od = RPCCaller.<xtreemfs_check_objectRequest, ObjectData> syncCall(SERVICES.OSD, RPCAuthentication.userService, RPCAuthentication.authNone, volumeOptions, uuidResolver, it, false, request, new CallGenerator<xtreemfs_check_objectRequest, ObjectData>() { @Override public RPCResponse<ObjectData> executeCall(InetSocketAddress server, Auth authHeader, UserCredentials userCreds, xtreemfs_check_objectRequest input) throws IOException, PosixErrorException { return osdServiceClient.xtreemfs_check_object(server, authHeader, userCreds, input); } }); } catch (IOException e) { if (Logging.isDebug()) Logging.logMessage(Logging.LEVEL_DEBUG, this, "IO error: %s", e.toString()); throw new IOException("operation aborted", e); } if (od.getInvalidChecksumOnOsd()) { throw new InvalidChecksumException("object " + objectNo + " has an invalid checksum"); } return od.getZeroPadding(); } FileHandleImplementation(VolumeImplementation volume, String clientUuid, FileInfo fileInfo, XCap xcap,
            UUIDIterator mrcUuidIterator, UUIDIterator osdUuidIterator, UUIDResolver uuidResolver,
            MRCServiceClient mrcServiceClient, OSDServiceClient osdServiceClient,
            Map<StripingPolicyType, StripeTranslator> stripeTranslators, boolean asyncWritesEnabled, Options options,
            Auth authBogus, UserCredentials userCredentialsBogus); }
FileHandleImplementation implements FileHandle, AdminFileHandle { @Override public int checkObjectAndGetSize(int replicaIndex, long objectNo) throws IOException, InvalidChecksumException { ObjectData od = null; RPCResponse<ObjectData> osdRsp = null; try { FileCredentials.Builder fcBuilder = FileCredentials.newBuilder(); fcBuilder.setXlocs(fileInfo.getXLocSet()); fcBuilder.setXcap(getXcap()); String fileId = Helper.extractGlobalFileIdFromXcap(fcBuilder.getXcap()); Replica r = getReplica(replicaIndex); String objOsd = r.getOsdUuids((int) objectNo % r.getStripingPolicy().getWidth()); UUIDIterator it = new UUIDIterator(); it.addUUID(objOsd); xtreemfs_check_objectRequest request = xtreemfs_check_objectRequest.newBuilder() .setFileCredentials(fcBuilder.build()).setFileId(fileId).setObjectNumber(objectNo) .setObjectVersion(0l).build(); od = RPCCaller.<xtreemfs_check_objectRequest, ObjectData> syncCall(SERVICES.OSD, RPCAuthentication.userService, RPCAuthentication.authNone, volumeOptions, uuidResolver, it, false, request, new CallGenerator<xtreemfs_check_objectRequest, ObjectData>() { @Override public RPCResponse<ObjectData> executeCall(InetSocketAddress server, Auth authHeader, UserCredentials userCreds, xtreemfs_check_objectRequest input) throws IOException, PosixErrorException { return osdServiceClient.xtreemfs_check_object(server, authHeader, userCreds, input); } }); } catch (IOException e) { if (Logging.isDebug()) Logging.logMessage(Logging.LEVEL_DEBUG, this, "IO error: %s", e.toString()); throw new IOException("operation aborted", e); } if (od.getInvalidChecksumOnOsd()) { throw new InvalidChecksumException("object " + objectNo + " has an invalid checksum"); } return od.getZeroPadding(); } FileHandleImplementation(VolumeImplementation volume, String clientUuid, FileInfo fileInfo, XCap xcap,
            UUIDIterator mrcUuidIterator, UUIDIterator osdUuidIterator, UUIDResolver uuidResolver,
            MRCServiceClient mrcServiceClient, OSDServiceClient osdServiceClient,
            Map<StripingPolicyType, StripeTranslator> stripeTranslators, boolean asyncWritesEnabled, Options options,
            Auth authBogus, UserCredentials userCredentialsBogus); @Override int read(UserCredentials userCredentials, byte[] data, int count, long offset); @Override int read(final UserCredentials userCredentials, final byte[] data, final int dataOffset, final int count,
            final long offset); @Override synchronized int write(UserCredentials userCredentials, byte[] data, int count, long offset); @Override synchronized int write(UserCredentials userCredentials, byte[] data, int dataOffset, int count, long offset); @Override void flush(); @Override void truncate(UserCredentials userCredentials, long newFileSize); @Override void truncate(UserCredentials userCredentials, long newFileSize, boolean updateOnlyMRC); @Override Stat getAttr(UserCredentials userCredentials); @Override Lock acquireLock(final UserCredentials userCredentials, final int processId, final long offset,
            final long length, final boolean exclusive, final boolean waitForLock); @Override Lock checkLock(final UserCredentials userCredentials, final int processId, final long offset,
            final long length, final boolean exclusive); @Override void releaseLock(final UserCredentials userCredentials, final int processId, final long offset,
            final long length, final boolean exclusive); @Override void releaseLock(UserCredentials userCredentials, Lock lock); @Override void releaseLockOfProcess(int processId); @Override void pingReplica(UserCredentials userCredentials, String osdUuid); @Override void close(); @Override String getGlobalFileId(); @Override List<Replica> getReplicasList(); @Override Replica getReplica(int replicaIndex); @Override StripingPolicy getStripingPolicy(); @Override StripingPolicy getStripingPolicy(int replicaIndex); @Override String getReplicaUpdatePolicy(); @Override long getNumObjects(UserCredentials userCredentials); @Override boolean checkAndMarkIfReadOnlyReplicaComplete(int replicaIndex, UserCredentials userCredentials); @Override int checkObjectAndGetSize(int replicaIndex, long objectNo); @Override long getSizeOnOSD(); @Override void repairObject(int replicaIndex, long objectNo); @Override String getLastOSDAddress(); }
FileHandleImplementation implements FileHandle, AdminFileHandle { @Override public int checkObjectAndGetSize(int replicaIndex, long objectNo) throws IOException, InvalidChecksumException { ObjectData od = null; RPCResponse<ObjectData> osdRsp = null; try { FileCredentials.Builder fcBuilder = FileCredentials.newBuilder(); fcBuilder.setXlocs(fileInfo.getXLocSet()); fcBuilder.setXcap(getXcap()); String fileId = Helper.extractGlobalFileIdFromXcap(fcBuilder.getXcap()); Replica r = getReplica(replicaIndex); String objOsd = r.getOsdUuids((int) objectNo % r.getStripingPolicy().getWidth()); UUIDIterator it = new UUIDIterator(); it.addUUID(objOsd); xtreemfs_check_objectRequest request = xtreemfs_check_objectRequest.newBuilder() .setFileCredentials(fcBuilder.build()).setFileId(fileId).setObjectNumber(objectNo) .setObjectVersion(0l).build(); od = RPCCaller.<xtreemfs_check_objectRequest, ObjectData> syncCall(SERVICES.OSD, RPCAuthentication.userService, RPCAuthentication.authNone, volumeOptions, uuidResolver, it, false, request, new CallGenerator<xtreemfs_check_objectRequest, ObjectData>() { @Override public RPCResponse<ObjectData> executeCall(InetSocketAddress server, Auth authHeader, UserCredentials userCreds, xtreemfs_check_objectRequest input) throws IOException, PosixErrorException { return osdServiceClient.xtreemfs_check_object(server, authHeader, userCreds, input); } }); } catch (IOException e) { if (Logging.isDebug()) Logging.logMessage(Logging.LEVEL_DEBUG, this, "IO error: %s", e.toString()); throw new IOException("operation aborted", e); } if (od.getInvalidChecksumOnOsd()) { throw new InvalidChecksumException("object " + objectNo + " has an invalid checksum"); } return od.getZeroPadding(); } FileHandleImplementation(VolumeImplementation volume, String clientUuid, FileInfo fileInfo, XCap xcap,
            UUIDIterator mrcUuidIterator, UUIDIterator osdUuidIterator, UUIDResolver uuidResolver,
            MRCServiceClient mrcServiceClient, OSDServiceClient osdServiceClient,
            Map<StripingPolicyType, StripeTranslator> stripeTranslators, boolean asyncWritesEnabled, Options options,
            Auth authBogus, UserCredentials userCredentialsBogus); @Override int read(UserCredentials userCredentials, byte[] data, int count, long offset); @Override int read(final UserCredentials userCredentials, final byte[] data, final int dataOffset, final int count,
            final long offset); @Override synchronized int write(UserCredentials userCredentials, byte[] data, int count, long offset); @Override synchronized int write(UserCredentials userCredentials, byte[] data, int dataOffset, int count, long offset); @Override void flush(); @Override void truncate(UserCredentials userCredentials, long newFileSize); @Override void truncate(UserCredentials userCredentials, long newFileSize, boolean updateOnlyMRC); @Override Stat getAttr(UserCredentials userCredentials); @Override Lock acquireLock(final UserCredentials userCredentials, final int processId, final long offset,
            final long length, final boolean exclusive, final boolean waitForLock); @Override Lock checkLock(final UserCredentials userCredentials, final int processId, final long offset,
            final long length, final boolean exclusive); @Override void releaseLock(final UserCredentials userCredentials, final int processId, final long offset,
            final long length, final boolean exclusive); @Override void releaseLock(UserCredentials userCredentials, Lock lock); @Override void releaseLockOfProcess(int processId); @Override void pingReplica(UserCredentials userCredentials, String osdUuid); @Override void close(); @Override String getGlobalFileId(); @Override List<Replica> getReplicasList(); @Override Replica getReplica(int replicaIndex); @Override StripingPolicy getStripingPolicy(); @Override StripingPolicy getStripingPolicy(int replicaIndex); @Override String getReplicaUpdatePolicy(); @Override long getNumObjects(UserCredentials userCredentials); @Override boolean checkAndMarkIfReadOnlyReplicaComplete(int replicaIndex, UserCredentials userCredentials); @Override int checkObjectAndGetSize(int replicaIndex, long objectNo); @Override long getSizeOnOSD(); @Override void repairObject(int replicaIndex, long objectNo); @Override String getLastOSDAddress();  }