@Test public void testWriteBackFileSizeAsync() throws Exception { String volumeName = "testWriteBackFileSizeAsync"; String fileName = "testfile"; int flags = SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber() | SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_RDWR.getNumber(); Client client = ClientFactory.createClient(ClientType.JAVA, dirAddress, userCredentials, null, options); client.start(); client.createVolume(mrcAddress, auth, userCredentials, volumeName); Volume volume = client.openVolume(volumeName, null, options); FileHandleImplementation fileHandle = (FileHandleImplementation) volume.openFile(userCredentials, fileName, flags, 0777); OSDWriteResponse.Builder responseBuilder = OSDWriteResponse.newBuilder(); responseBuilder.setSizeInBytes(13337); responseBuilder.setTruncateEpoch(20); OSDWriteResponse response = responseBuilder.build(); fileHandle.setOsdWriteResponseForAsyncWriteBack(response); fileHandle.writeBackFileSizeAsync(); Thread.sleep(2000); RPCResponse<getattrResponse> r = mrcClient.getattr(testEnv.getMRCAddress(), auth, userCredentials, volumeName, fileName, 0l); getattrResponse response2 = r.get(); assertEquals(response.getSizeInBytes(), response2.getStbuf().getSize()); assertEquals(response.getTruncateEpoch(), response2.getStbuf().getTruncateEpoch()); r.freeBuffers(); }
protected void writeBackFileSizeAsync() throws IOException, PosixErrorException, AddressToUUIDNotFoundException { xtreemfs_update_file_sizeRequest.Builder rqBuilder = xtreemfs_update_file_sizeRequest.newBuilder(); synchronized (this) { if (osdWriteResponseForAsyncWriteBack == null) { return; } if (Logging.isDebug()) { Logging.logMessage(Logging.LEVEL_DEBUG, Category.misc, this, "updateFileSize: %s " + "#bytes: %s", fileInfo.getPath(), osdWriteResponseForAsyncWriteBack.getSizeInBytes()); } rqBuilder.setXcap(xcap).setOsdWriteResponse(osdWriteResponseForAsyncWriteBack.toBuilder()); } rqBuilder.setCloseFile(false); String address = uuidResolver.uuidToAddress(mrcUuidIterator.getUUID()); InetSocketAddress server = RPCCaller.getInetSocketAddressFromAddress(address, SERVICES.MRC); RPCResponse<timestampResponse> r = mrcServiceClient.xtreemfs_update_file_size(server, authBogus, userCredentialsBogus, rqBuilder.build()); final FileHandleImplementation fileHandle = this; r.registerListener(new RPCResponseAvailableListener<timestampResponse>() { @Override public void responseAvailable(RPCResponse<timestampResponse> r) { try { r.get(); fileInfo.asyncFileSizeUpdateResponseHandler(osdWriteResponseForAsyncWriteBack, fileHandle, true); } catch (Exception e) { if (Logging.isDebug()) { Logging.logMessage(Logging.LEVEL_DEBUG, this, "renewXcapAsync: The following " + "error occurred during the async all: ", e.getMessage()); } fileInfo.asyncFileSizeUpdateResponseHandler(osdWriteResponseForAsyncWriteBack, fileHandle, false); } finally { r.freeBuffers(); } } }); }
FileHandleImplementation implements FileHandle, AdminFileHandle { protected void writeBackFileSizeAsync() throws IOException, PosixErrorException, AddressToUUIDNotFoundException { xtreemfs_update_file_sizeRequest.Builder rqBuilder = xtreemfs_update_file_sizeRequest.newBuilder(); synchronized (this) { if (osdWriteResponseForAsyncWriteBack == null) { return; } if (Logging.isDebug()) { Logging.logMessage(Logging.LEVEL_DEBUG, Category.misc, this, "updateFileSize: %s " + "#bytes: %s", fileInfo.getPath(), osdWriteResponseForAsyncWriteBack.getSizeInBytes()); } rqBuilder.setXcap(xcap).setOsdWriteResponse(osdWriteResponseForAsyncWriteBack.toBuilder()); } rqBuilder.setCloseFile(false); String address = uuidResolver.uuidToAddress(mrcUuidIterator.getUUID()); InetSocketAddress server = RPCCaller.getInetSocketAddressFromAddress(address, SERVICES.MRC); RPCResponse<timestampResponse> r = mrcServiceClient.xtreemfs_update_file_size(server, authBogus, userCredentialsBogus, rqBuilder.build()); final FileHandleImplementation fileHandle = this; r.registerListener(new RPCResponseAvailableListener<timestampResponse>() { @Override public void responseAvailable(RPCResponse<timestampResponse> r) { try { r.get(); fileInfo.asyncFileSizeUpdateResponseHandler(osdWriteResponseForAsyncWriteBack, fileHandle, true); } catch (Exception e) { if (Logging.isDebug()) { Logging.logMessage(Logging.LEVEL_DEBUG, this, "renewXcapAsync: The following " + "error occurred during the async all: ", e.getMessage()); } fileInfo.asyncFileSizeUpdateResponseHandler(osdWriteResponseForAsyncWriteBack, fileHandle, false); } finally { r.freeBuffers(); } } }); } }
FileHandleImplementation implements FileHandle, AdminFileHandle { protected void writeBackFileSizeAsync() throws IOException, PosixErrorException, AddressToUUIDNotFoundException { xtreemfs_update_file_sizeRequest.Builder rqBuilder = xtreemfs_update_file_sizeRequest.newBuilder(); synchronized (this) { if (osdWriteResponseForAsyncWriteBack == null) { return; } if (Logging.isDebug()) { Logging.logMessage(Logging.LEVEL_DEBUG, Category.misc, this, "updateFileSize: %s " + "#bytes: %s", fileInfo.getPath(), osdWriteResponseForAsyncWriteBack.getSizeInBytes()); } rqBuilder.setXcap(xcap).setOsdWriteResponse(osdWriteResponseForAsyncWriteBack.toBuilder()); } rqBuilder.setCloseFile(false); String address = uuidResolver.uuidToAddress(mrcUuidIterator.getUUID()); InetSocketAddress server = RPCCaller.getInetSocketAddressFromAddress(address, SERVICES.MRC); RPCResponse<timestampResponse> r = mrcServiceClient.xtreemfs_update_file_size(server, authBogus, userCredentialsBogus, rqBuilder.build()); final FileHandleImplementation fileHandle = this; r.registerListener(new RPCResponseAvailableListener<timestampResponse>() { @Override public void responseAvailable(RPCResponse<timestampResponse> r) { try { r.get(); fileInfo.asyncFileSizeUpdateResponseHandler(osdWriteResponseForAsyncWriteBack, fileHandle, true); } catch (Exception e) { if (Logging.isDebug()) { Logging.logMessage(Logging.LEVEL_DEBUG, this, "renewXcapAsync: The following " + "error occurred during the async all: ", e.getMessage()); } fileInfo.asyncFileSizeUpdateResponseHandler(osdWriteResponseForAsyncWriteBack, fileHandle, false); } finally { r.freeBuffers(); } } }); } 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 { protected void writeBackFileSizeAsync() throws IOException, PosixErrorException, AddressToUUIDNotFoundException { xtreemfs_update_file_sizeRequest.Builder rqBuilder = xtreemfs_update_file_sizeRequest.newBuilder(); synchronized (this) { if (osdWriteResponseForAsyncWriteBack == null) { return; } if (Logging.isDebug()) { Logging.logMessage(Logging.LEVEL_DEBUG, Category.misc, this, "updateFileSize: %s " + "#bytes: %s", fileInfo.getPath(), osdWriteResponseForAsyncWriteBack.getSizeInBytes()); } rqBuilder.setXcap(xcap).setOsdWriteResponse(osdWriteResponseForAsyncWriteBack.toBuilder()); } rqBuilder.setCloseFile(false); String address = uuidResolver.uuidToAddress(mrcUuidIterator.getUUID()); InetSocketAddress server = RPCCaller.getInetSocketAddressFromAddress(address, SERVICES.MRC); RPCResponse<timestampResponse> r = mrcServiceClient.xtreemfs_update_file_size(server, authBogus, userCredentialsBogus, rqBuilder.build()); final FileHandleImplementation fileHandle = this; r.registerListener(new RPCResponseAvailableListener<timestampResponse>() { @Override public void responseAvailable(RPCResponse<timestampResponse> r) { try { r.get(); fileInfo.asyncFileSizeUpdateResponseHandler(osdWriteResponseForAsyncWriteBack, fileHandle, true); } catch (Exception e) { if (Logging.isDebug()) { Logging.logMessage(Logging.LEVEL_DEBUG, this, "renewXcapAsync: The following " + "error occurred during the async all: ", e.getMessage()); } fileInfo.asyncFileSizeUpdateResponseHandler(osdWriteResponseForAsyncWriteBack, fileHandle, false); } finally { r.freeBuffers(); } } }); } 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 { protected void writeBackFileSizeAsync() throws IOException, PosixErrorException, AddressToUUIDNotFoundException { xtreemfs_update_file_sizeRequest.Builder rqBuilder = xtreemfs_update_file_sizeRequest.newBuilder(); synchronized (this) { if (osdWriteResponseForAsyncWriteBack == null) { return; } if (Logging.isDebug()) { Logging.logMessage(Logging.LEVEL_DEBUG, Category.misc, this, "updateFileSize: %s " + "#bytes: %s", fileInfo.getPath(), osdWriteResponseForAsyncWriteBack.getSizeInBytes()); } rqBuilder.setXcap(xcap).setOsdWriteResponse(osdWriteResponseForAsyncWriteBack.toBuilder()); } rqBuilder.setCloseFile(false); String address = uuidResolver.uuidToAddress(mrcUuidIterator.getUUID()); InetSocketAddress server = RPCCaller.getInetSocketAddressFromAddress(address, SERVICES.MRC); RPCResponse<timestampResponse> r = mrcServiceClient.xtreemfs_update_file_size(server, authBogus, userCredentialsBogus, rqBuilder.build()); final FileHandleImplementation fileHandle = this; r.registerListener(new RPCResponseAvailableListener<timestampResponse>() { @Override public void responseAvailable(RPCResponse<timestampResponse> r) { try { r.get(); fileInfo.asyncFileSizeUpdateResponseHandler(osdWriteResponseForAsyncWriteBack, fileHandle, true); } catch (Exception e) { if (Logging.isDebug()) { Logging.logMessage(Logging.LEVEL_DEBUG, this, "renewXcapAsync: The following " + "error occurred during the async all: ", e.getMessage()); } fileInfo.asyncFileSizeUpdateResponseHandler(osdWriteResponseForAsyncWriteBack, fileHandle, false); } finally { r.freeBuffers(); } } }); } 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();  }