/* * This Function is to be Called when a Entire User Needs to be Moved */ public bool sendsynchUser(UserFileSystem file, OOBHandler oobhandle, Group group, List<Address> where) { try { Logger.Debug ("File Operations Synch - sendsynchUser >> BEGIN"); bool operationResult = false; string fileName = FileServerComm.getInstance ().transManager.generateTransactionId (file.metadata.clientId); Transaction trans = new Transaction (fileName); if (true == FileServerComm.getInstance ().transManager.insertTransaction (trans)) { try { MemoryMappedFile transferFile = null; int writtenBytesLength = 0; transferFile = oobhandle.serializeIntoMemoryMappedFile (fileName, file, ref writtenBytesLength); OOBTransaction oobtrabs = new OOBTransaction (fileName, IsisSystem.GetMyAddress (), writtenBytesLength); oobhandle.sendOOBData (group, transferFile, fileName, where); trans.waitTillSignalled (); operationResult = !trans.isTimedOut; if (operationResult) { group.OrderedSend (FileServerComm.UpdateUser, oobtrabs); trans.waitTillSignalled (); operationResult = !trans.isTimedOut; } FileServerComm.getInstance ().transManager.removeAndGetTransaction (fileName); operationResult = !trans.isTimedOut; } catch (Exception e) { Logger.Debug ("Exception during File Operations Synch - sendsynchUser" + e.ToString ()); } } return operationResult; } catch (Exception e) { Logger.Debug ("File Operations Synch - sendsynchUser >> Encountered Exception : " + e.ToString()); return false; } }
/* * This Function is called when a New User Is Added or the Meta Data of the User Needs to be Changed and Synched */ public bool sendsynchUserMetaData(UserMetaData data, OOBHandler handler, Group group, bool waitToFinish = true) { try { Logger.Debug ("File Operations Synch - sendsynchUserMetaData >> BEGIN"); bool operationResult = false; if (waitToFinish) { string transactionId = FileServerComm.getInstance ().transManager.generateTransactionId (data.clientId); Transaction trans = new Transaction (transactionId); if (true == FileServerComm.getInstance ().transManager.insertTransaction (trans)) { UserMetaDataSync sync = new UserMetaDataSync (transactionId, IsisSystem.GetMyAddress (), data); group.OrderedSend (FileServerComm.UpdateUserMetaData, sync); Logger.Debug ("File Operations Synch - Making a Ordered Send"); trans.waitTillSignalled (); FileServerComm.getInstance ().transManager.removeAndGetTransaction (transactionId); operationResult = !trans.isTimedOut; } else { Logger.Debug ("File Operations Synch - sendsynchUserMetaData >> Generation of Transaction ID Failed: " + transactionId); } } else { UserMetaDataSync sync = new UserMetaDataSync ("", IsisSystem.GetMyAddress (), data); group.OrderedSend (FileServerComm.UpdateUserMetaData, sync); operationResult = true; } Logger.Debug ("File Operations Synch - sendsynchUserMetaData >> END Operation Status " + operationResult); return operationResult; } catch (Exception e) { Logger.Debug("File Operations Synch - sendsynchUserMetaData threw an Exception " + e.ToString()); return false; } }
public bool sendSynchUnShareRequest(UnShareFileWithUser request, OOBHandler handler, Group group, bool waitToFinish = true) { try { Logger.Debug ("File Operations Synch - sendSynchUnShareRequest >> BEGIN"); bool operationResult = false; if (waitToFinish) { string transactionId = FileServerComm.getInstance ().transManager.generateTransactionId (request.filename); Transaction trans = new Transaction (transactionId); if (true == FileServerComm.getInstance ().transManager.insertTransaction (trans)) { SyncUnSharedUser sync = new SyncUnSharedUser (transactionId, IsisSystem.GetMyAddress (), request.clientId, request.password, request.filename, request.sharedWithUser); group.OrderedSend (FileServerComm.UnshareWithUser, sync); trans.waitTillSignalled (); FileServerComm.getInstance ().transManager.removeAndGetTransaction (transactionId); operationResult = !trans.isTimedOut; } else { Logger.Debug ("File Operations Synch - sendsynchdeleteFile >> Generation of Transaction ID Failed: " + transactionId); } } else { SyncUnSharedUser sync = new SyncUnSharedUser ("", IsisSystem.GetMyAddress (), request.clientId, request.password, request.filename, request.sharedWithUser); group.OrderedSend (FileServerComm.UnshareWithUser, sync); operationResult = true; } Logger.Debug ("File Operations Synch - sendsynchdeleteFileFromMemory >> END Operation Status " + operationResult); return operationResult; } catch (Exception e) { Logger.Debug("File Operations Synch - sendSynchUnShareRequest Encountered a Exeption: " + e.ToString()); return false; } }
/* This Function is called when a File Needs to be Delete from the Memory This could be when the LRU replacement policy is chosen and we need to delete a File From memory */ public bool sendsynchdeleteFileFromMemory(FileMetaData filemetadata, OOBHandler handler, Group group, bool waitToFinish = true) { try { Logger.Debug ("File Operations Synch - sendsynchdeleteFileFromMemory >> BEGIN"); bool operationResult = false; if (waitToFinish) { string transactionId = FileServerComm.getInstance ().transManager.generateTransactionId (filemetadata.filepath); Transaction trans = new Transaction (transactionId); if (true == FileServerComm.getInstance ().transManager.insertTransaction (trans)) { FileMetaDataSync sync = new FileMetaDataSync (transactionId, IsisSystem.GetMyAddress (), filemetadata); group.OrderedSend (FileServerComm.DeleteFileFromMemory, sync); trans.waitTillSignalled (); FileServerComm.getInstance ().transManager.removeAndGetTransaction (transactionId); operationResult = !trans.isTimedOut; } else { Logger.Debug ("File Operations Synch - sendsynchUserMetaData >> Generation of Transaction ID Failed: " + transactionId); } } else { FileMetaDataSync sync = new FileMetaDataSync ("", IsisSystem.GetMyAddress (), filemetadata); group.OrderedSend (FileServerComm.DeleteFileFromMemory, sync); operationResult = true; } Logger.Debug ("File Operations Synch - sendsynchdeleteFileFromMemory >> END Operation Status " + operationResult); return operationResult; } catch (Exception e) { Logger.Debug("File Operations Synch - sendsynchdeleteFileFromMemory Encountered Exception: " + e.ToString()); return false; } }
/* This Function is called when a New File Needs to be Added into the memory */ public bool sendsynchaddFileToMemory(string UserName, UserFile file, OOBHandler oobhandle, Group group, List<Address> where) { try { Logger.Debug ("File Operations Synch - sendsynchaddFileToMemory >> BEGIN"); bool operationResult = false; MemoryMappedFile transferFile = null; string fileName = FileServerComm.getInstance ().transManager.generateTransactionId (UserName + "_" + file.filemetadata.filepath); Transaction trans = new Transaction (fileName); if (true == FileServerComm.getInstance ().transManager.insertTransaction (trans)) { try { int writtenBytesLength = 0; transferFile = oobhandle.serializeIntoMemoryMappedFile (fileName, file,ref writtenBytesLength); oobhandle.sendOOBData (group, transferFile, fileName, where); trans.waitTillSignalled (); Logger.Debug ("File Operations Synch - sendsynchaddFileToMemory >> OOB Transfer of Data Complete for : " + file.filemetadata.filepath); operationResult = !trans.isTimedOut; OOBTransaction oobtrabs = new OOBTransaction (fileName, IsisSystem.GetMyAddress (), writtenBytesLength); if (operationResult) { group.OrderedSend (FileServerComm.SaveFileToMemory, oobtrabs); trans.waitTillSignalled (); Logger.Debug ("File Operations Synch - sendsynchaddFileToMemory >> Ordered Send Complete Complete for : " + file.filemetadata.filepath); operationResult = !trans.isTimedOut; } FileServerComm.getInstance ().transManager.removeAndGetTransaction (fileName); operationResult = !trans.isTimedOut; } catch (Exception e) { Logger.Debug ("Exception during File Operations Synch - sendsynchaddFileToMemory" + e.ToString ()); FileServerComm.getInstance ().transManager.removeAndGetTransaction (fileName); operationResult = false; } } else { Logger.Debug ("File Operations Synch - sendsynchaddFileToMemory >> Generation of Transaction ID Failed: " + fileName); } return operationResult; } catch (Exception e) { Logger.Debug("Caught Exception " + e.ToString()); } return false; }
void handleBootStrappingRequest(Group group, OOBHandler oobhandle, InMemoryFileSystem fileSystem, string requestName, Address recvdFrom) { if (state.currState == eBootStrapState.BootStrappingComplete) { Logger.Debug("handleBootStrappingRequest , Received from " + recvdFrom.ToStringVerboseFormat()); BootStrappingCheckPoint initialStage = null; initialStage = new BootStrappingCheckPoint ("Boot Strapping Begin", FileServerComm.BootStrapBegin, IsisSystem.GetMyAddress (), SUCCESS, 0); Logger.Debug("Sending a BootStrapping Begin , Response to " + recvdFrom.ToStringVerboseFormat()); group.RawP2PSend (recvdFrom, FileServerComm.BootStrapBegin, initialStage); MemoryMappedFile transferFile = null; int currentUserIndex = 0; int numberOfUsersCurrentBatch = 0; List<string> users = fileSystem.GetInMemoryUserList (); InMemoryFileSystem tempFileSystem = new InMemoryFileSystem (false); //Yayy Lets Begin Doing Some Boot Strapping try { Logger.Debug("Number of Users to BootStrap and Send " + users.Count); while (currentUserIndex < users.Count) { UserFileSystem userfilesys = fileSystem.GetClonedInMemoryUserFileSystem (users [currentUserIndex]); numberOfUsersCurrentBatch++; Logger.Debug("Adding User to the BootStrap : " + users[currentUserIndex]); tempFileSystem.addFSToMapSynchronized (userfilesys, users [currentUserIndex]); currentUserIndex++; if (numberOfUsersCurrentBatch == BatchSize) { //Let's Make a OOB File and Transfer the Data string currentFileName = FileServerComm.getInstance ().transManager.generateTransactionId (); bool operationResult = false; numberOfUsersCurrentBatch = 0; Transaction trans = new Transaction (currentFileName); FileServerComm.getInstance ().transManager.insertTransaction (trans); int writtenBytesLength = 0; transferFile = oobhandle.serializeIntoMemoryMappedFile (currentFileName, tempFileSystem, ref writtenBytesLength); BootStrappingCheckPoint continueBootStrap = null; continueBootStrap = new BootStrappingCheckPoint (currentFileName, FileServerComm.BootStrapContinue, IsisSystem.GetMyAddress (), SUCCESS, writtenBytesLength); List<Address> where = new List<Address>(); where.Add(recvdFrom); where.Add (IsisSystem.GetMyAddress ()); oobhandle.sendOOBData (group, transferFile, currentFileName, where); trans.waitTillSignalled (); operationResult = !trans.isTimedOut; if (operationResult) { group.RawP2PSend (recvdFrom, FileServerComm.BootStrapContinue, continueBootStrap); trans.waitTillSignalled (); operationResult = !trans.isTimedOut; } else { Logger.Debug ("Sending BootStraping Request Timed Out, Quit Out of BootStrapping partcicipation"); return; } tempFileSystem = new InMemoryFileSystem (); } } //Lets Throw out the Remaining Users if (numberOfUsersCurrentBatch != 0) { string currentFileName = FileServerComm.getInstance ().transManager.generateTransactionId (); Transaction trans = new Transaction (currentFileName); FileServerComm.getInstance ().transManager.insertTransaction (trans); bool currentOperationResult = false; int writtenBytesLength = 0; transferFile = oobhandle.serializeIntoMemoryMappedFile (currentFileName, tempFileSystem, ref writtenBytesLength); BootStrappingCheckPoint _continue = null; _continue = new BootStrappingCheckPoint (currentFileName, FileServerComm.BootStrapContinue, IsisSystem.GetMyAddress (), SUCCESS, writtenBytesLength); List<Address> where = new List<Address>(); where.Add(recvdFrom); where.Add (IsisSystem.GetMyAddress ()); oobhandle.sendOOBData (group, transferFile, currentFileName, where); trans.waitTillSignalled (); currentOperationResult = !trans.isTimedOut; if (currentOperationResult) { group.RawP2PSend (recvdFrom, FileServerComm.BootStrapContinue, _continue); trans.waitTillSignalled (); currentOperationResult = !trans.isTimedOut; } else { Logger.Debug ("Sending BootStraping Request Timed Out, Quit Out of BootStrapping partcicipation"); return; } tempFileSystem = new InMemoryFileSystem (); numberOfUsersCurrentBatch = 0; } Logger.Debug("Sending a Boot Strap End Response to " + recvdFrom.ToString()); BootStrappingCheckPoint finalStage = null; finalStage = new BootStrappingCheckPoint ("Yayyy Finally Done", FileServerComm.BootStrapEnd, IsisSystem.GetMyAddress (), SUCCESS, 0); group.RawP2PSend (recvdFrom, FileServerComm.BootStrapEnd, finalStage); return; } catch (Exception e) { Logger.Debug("Caught an Exception : " + e.ToString()); BootStrappingCheckPoint _exception = null; _exception = new BootStrappingCheckPoint (e.ToString (), FileServerComm.BootStrapException, IsisSystem.GetMyAddress (), FAILURE, 0); group.P2PSend (recvdFrom, FileServerComm.BootStrapException, _exception); return; } } else { Logger.Debug("Node is Not in the State of Boot Strapping, Ignore this Request and Keep Calm"); } }
public bool insertTransaction(Transaction trans) { lock (this.privateLock) { if (!this.transaction.ContainsKey (trans.transactionName)) { this.transaction.Add (trans.transactionName, trans); return true; } return false; } }