Example #1
0
        //Main Operations
        //Create Operation
        public FileMetadata create(string filename, int numberOfDataServers, int readQuorum, int writeQuorum)
        {
            LogPrint("Create Operation");
            LogPrint("\t Filename: " + filename + " Number of Data Servers: " + numberOfDataServers +
                " ReadQuorum: " + readQuorum + " Write Quorum: " + writeQuorum);

            if (!_isMaster)
            {
                FileMetadata fileToReturn = _metadataMasterActualProxy.create(filename, numberOfDataServers, readQuorum, writeQuorum);
                LogPrint("Sucessfull!");
                return fileToReturn;
            }

            lock (this)
            {
                //Verification if the file with this filename already exists, if it does, returns that file
                if (_filesMetadata.ContainsKey(filename))
                {
                    return _filesMetadata[filename];
                }

                //Associates this filename with a unique filename for local DataServer storage
                string associatedFilename = generateFilenameForDataServers();
                _dataServersAssociatedFilenames.Add(filename, associatedFilename);
                //Creates an association between filename and a list with data servers to fill in
                _localFilesDataServers.Add(associatedFilename, new List<string>());

                //Association between dataServers and local filenames for the filename asked
                List<Tuple<string, string>> dataServersLocalFilenames = new List<Tuple<string, string>>();

                //Computation about who will have filename asked to create and store it in the dataServersLocalFilenames list
                Dictionary<string, int> sortedDataServersNumberOfFiles = _dataServersNumberOfFiles.OrderBy(x => x.Value).ToDictionary(p => p.Key, q => q.Value);

                int counter = 0;
                foreach (string dataServerName in sortedDataServersNumberOfFiles.Keys)
                {
                    _dataServersProxys[dataServerName].createFilename(associatedFilename);
                    _dataServersNumberOfFiles[dataServerName] = _dataServersNumberOfFiles[dataServerName] + 1;
                    _localFilesDataServers[associatedFilename].Add(dataServerName);

                    dataServersLocalFilenames.Add(new Tuple<string, string>(_dataServersURLS[dataServerName], associatedFilename));

                    if (++counter == numberOfDataServers)
                        break;
                }

                // If there are missing DataServers to associate to this file, it creates a task for it (which include the number of DataServers missing to associate to this file)
                // and it will be executed when appropriate
                if (counter < numberOfDataServers)
                {
                    _filesWithMissingDataServers.Add(filename, numberOfDataServers - counter);
                }

                FileMetadata newFileMetadata = new FileMetadata(filename, numberOfDataServers, readQuorum, writeQuorum, dataServersLocalFilenames);

                _filesMetadata.Add(filename, newFileMetadata);

                //Update replicas
                if (_isMaster)
                    updateMetadataServerReplicas();

                LogPrint("Sucessfull!");

                return newFileMetadata;
            }
        }
Example #2
0
        private void saveFileMetadata(FileMetadata fileMetadata)
        {
            _filesInfo[_registerPosition] = new Tuple<FileMetadata, PADI_FS_Library.File>(fileMetadata,null);

            if (++_registerPosition == numberOfRegisters)
                _registerPosition = 0;
        }