예제 #1
0
            public override void Configure(Funq.Container container)
            {
                Plugins.Add (new RequestLogsFeature ());
                    this.Config.DefaultContentType = "Json";
                    //container.RegisterAutoWired<InMemoryFileSystem>();

                    InMemoryFileSystem fileSystem = new InMemoryFileSystem ();
                    container.Register<InMemoryFileSystem> (fileSystem);

                    Console.WriteLine ("Application_Start ---->. Begin");

                    //Start the ISIS System
                    IsisSystem.Start ();

                    Console.WriteLine ("ISIS Started :)");

                    FileServerComm.fileServerGroupName = "FileServer";
                    FileServerComm fileSrvComm = FileServerComm.getInstance ();

                    fileSrvComm.getFileHandler ().filesystem = fileSystem;

                    System.IO.StreamReader file = new System.IO.StreamReader ("bootstrap.txt");
                    string line = file.ReadLine ();
                    Console.WriteLine (line);

                    bool isBootStrap = false;
                    if (line.Equals ("1")) {
                        isBootStrap = true;
                    }

                    fileSrvComm.ApplicationStartup(isBootStrap,FileServerComm.fileServerGroupName);

                    Console.WriteLine("Application_Start. End");
            }
예제 #2
0
 public BootStrap()
 {
     Logger.Debug ("BootStrapping, This should be Fun");
     waitBootStrap = new Semaphore(0,1);
     state = new BootStrappingState();
     fileSystem = new InMemoryFileSystem (true);
 }
예제 #3
0
        public void doDiff(InMemoryFileSystem currentFileSystem)
        {
            try {
                List<UserFileSystem> needInsertions = new List<UserFileSystem>();

                foreach (KeyValuePair<string, UserFileSystem> entry in  fileSystem.clientToFileSystemMap) {
                    UserFileSystem newFileSystem = entry.Value;
                    UserFileSystem oldFileSystem = currentFileSystem.getUserFSFromMapSynchronized (entry.Key);

                    if (null != oldFileSystem) {
                        mergeUserFileSystems (newFileSystem, oldFileSystem);
                    }
                    else {
                        needInsertions.Add(newFileSystem);
                    }
                }
                foreach(UserFileSystem tempFileSystem in needInsertions) {
                    Logger.Debug("New Insertions to the FIle System " + tempFileSystem.metadata.clientId);
                    currentFileSystem.addFSToMapSynchronized(tempFileSystem,tempFileSystem.metadata.clientId);
                }
            } catch (Exception e) {
                Logger.Debug("Received an Exception: " + e.ToString());
            }
        }
예제 #4
0
        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");
            }
        }
예제 #5
0
        public void resetBootStrappingState()
        {
            Logger.Debug ("BootStrapping, resetBootStrappingState()");

            fileSystem = null;
            state.reset();

            fileSystem = new InMemoryFileSystem ();
        }