public void registerOperation(MetaDataServer md, MetaDataOperation operation) { Console.WriteLine("registerOperation: " + operation + (operation == null ? "NULL" : "" + operation.OperationId)); if (md == null || operation == null) { throw new ArgumentNullException("RegisterOperation - Expected a MDS and an operation [ MDS:" + md + ", Operation: " + operation + " ]"); } int operationId; lock (typeof(MetaDataLog)) { operationId = NextId++; } if (md.getReplicationHandler().IsMaster) { operation.OperationId = operationId; } if (!log.Contains(operation)) { log.Add(operation); } md.getReplicationHandler().syncOperation(operation); }
private void executeOperation(MetaDataOperation operation) { if (replicationHandler.IsMaster) { safeExecuteOperation(operation); } else { Console.WriteLine("#MDS " + Id + " [SLAVE] - " + operation); int masterId = replicationHandler.MasterNodeId; throw new NotMasterException("please execute the operation on the master: " + masterId, masterId); } }
private void safeExecuteOperation(MetaDataOperation operation) { if (isFailing) { throw new Exception("MDS " + Id + " is failing"); } else if (isRecovering) { requestsQueue.Enqueue(operation); } else { Console.WriteLine("#MDS " + Id + (replicationHandler.IsMaster ? " [MASTER] - " : " [SLAVE] ") + operation); Log.registerOperation(this, operation); operation.execute(this); Log.incrementStatus(); } }
public void syncOperation(MetaDataOperation operation) { if (IsMaster) { List<MetaDataOperation> operations = new List<MetaDataOperation>(); operations.Add(operation); sendAliveMessage(new MetaDataServerAliveMessage(MetadataServerId, IsMaster, operations)); } }