public override void execute(MetaDataServer md) { if ((WriteQuorum > NumberOfDataServers) || (ReadQuorum > NumberOfDataServers)) { throw new CreateFileException("Invalid quorums values in create " + Filename); } if (md.FileMetadata.ContainsKey(Filename)) { throw new CreateFileException("#MDS.create - The file " + Filename + " already exists "); } // List<ServerObjectWrapper> newFileDataServers = getFirstServers(md, NumberOfDataServers); List<ServerObjectWrapper> newFileDataServers = md.getSortedServers(NumberOfDataServers); FileMetadata newFileMetadata = new FileMetadata(Filename, NumberOfDataServers, ReadQuorum, WriteQuorum, newFileDataServers); md.FileMetadata.Add(Filename, newFileMetadata); md.addMetadataLock(Filename, new ManualResetEvent(false)); md.getMigratingFiles().Add(Filename, new List<Tuple<string, string>>()); Console.WriteLine("#MDS: Created " + Filename); md.makeCheckpoint(); Result = md.FileMetadata[Filename]; }
public override void execute(MetaDataServer md) { if (!md.FileMetadata.ContainsKey(Filename)) { throw new OpenFileException("#MDS.open - File " + Filename + " does not exist"); } else if (md.FileMetadata[Filename].Clients.Contains(ClientID)) { Console.WriteLine("#MDS.open - File " + Filename + " is already open for user " + ClientID); Result = md.FileMetadata[Filename]; return; } else { Console.WriteLine("#MDS: opening file: " + Filename); lock (Filename) { md.FileMetadata[Filename].IsOpen = true; md.FileMetadata[Filename].Clients.Add(ClientID); md.makeCheckpoint(); Result = md.FileMetadata[Filename]; } } }
//receives a new filemetadata, //inserts the file in a roundRobin manner and returns //the position in witch the fileMetadata was saved public int addFileMetadata(FileMetadata fileMetadata) { int fileMetadataPosition = (containsFileMetadata(fileMetadata.FileName)) ? getPositionOf(fileMetadata.FileName) : findFirstFreePosition(); fileMetadata.IsOpen = true; Metadata[fileMetadataPosition] = fileMetadata; return fileMetadataPosition; }
private static void printReceivedDataServers(FileMetadata fileMetadata) { Console.Write("#Client: available data servers for " + fileMetadata.FileName + " :\r\n\t[ "); foreach (ServerObjectWrapper server in fileMetadata.FileServers) { Console.Write(server.Id + " "); } Console.WriteLine("]"); }
private Task<File> createAsyncTask(FileMetadata fileMetadata, int ds) { IDataServer dataServer = fileMetadata.FileServers[ds].getObject<IDataServer>(); return Task<File>.Factory.StartNew(() => { return dataServer.read(fileMetadata.FileName); } ); }
public double getFileAccesses(FileMetadata file) { double weight = 0; if (FileAccesses.ContainsKey(file.FileName)) { foreach (KeyValuePair<String, FileAccessCounter> entry in FileAccesses[file.FileName]) { FileAccessCounter fileCounter = entry.Value; weight += (fileCounter.ReadCounter) + (fileCounter.ReadVersionCounter) + (fileCounter.WriteCounter); } } return weight; }
public bool dataServerContainsFile(FileMetadata fileMetaData, string dsID) { foreach (ServerObjectWrapper server in fileMetaData.FileServers) { if (server.Id.Equals(dsID)) { return true; } } return false; }
private Task createAsyncWriteTask(FileMetadata fileMetadata, int ds) { IDataServer dataServer = fileMetadata.FileServers[ds].getObject<IDataServer>(); return Task.Factory.StartNew(() => { dataServer.write(NewFile); }); }
private Task<int> createAsyncTask(FileMetadata fileMetadata, int ds) { IDataServer dataServer = fileMetadata.FileServers[ds].getObject<IDataServer>(); return Task<int>.Factory.StartNew(() => { /*try { return dataServer.readFileVersion(FileName); } catch (Exception) { return 0; } }*/ return dataServer.readFileVersion(FileName); } ); }