private Response HandleTransactionMessage(Message txnMessage)
        {
            bool handledOk = false;

            switch (txnMessage.Header.ToLowerInvariant())
            {
            case "txn":
                var updateTransaction = ClusterUpdateTransaction.FromMessage(txnMessage);
                handledOk = _requestHandler.ProcessSlaveTransaction(updateTransaction);
                break;

            case "spu":
                var sparqlTransaction = ClusterSparqlTransaction.FromMessage(txnMessage);
                handledOk = _requestHandler.ProcessSlaveTransaction(sparqlTransaction);
                break;

            case "+store":
                handledOk = _requestHandler.CreateStore(txnMessage.Args);
                break;

            case "-store":
                handledOk = _requestHandler.DeleteStore(txnMessage.Args);
                break;
            }
            return(new Response(handledOk ? Message.ACK : Message.NAK));
        }
 private bool SendTransactions(SyncContext context, Func <SyncContext, Message, bool> messageSink, IEnumerable <ITransactionInfo> transactionsToSend, string storeId,
                               Guid prevId)
 {
     foreach (var txn in transactionsToSend.Where(t => t.TransactionStatus == TransactionStatus.CompletedOk))
     {
         if (txn.TransactionType == TransactionType.UpdateTransaction)
         {
             var job = _serverCore.LoadTransaction(storeId, txn);
             if (job is UpdateTransaction)
             {
                 var updateJob       = job as UpdateTransaction;
                 var syncTransaction = new ClusterUpdateTransaction
                 {
                     StoreId       = storeId,
                     PrevTxnId     = prevId,
                     JobId         = txn.JobId,
                     Preconditions = updateJob.Preconditions,
                     Deletes       = updateJob.DeletePatterns,
                     Inserts       = updateJob.InsertData
                 };
                 if (!messageSink(context, syncTransaction.AsMessage()))
                 {
                     // If message sink stops accepting messages, fail the entire sync process immediately
                     return(false);
                 }
             }
             else
             {
                 return(false);
             }
         }
         else if (txn.TransactionType == TransactionType.SparqlUpdateTransaction)
         {
             var job = _serverCore.LoadTransaction(storeId, txn);
             if (job is SparqlUpdateJob)
             {
                 var sparqlJob       = job as SparqlUpdateJob;
                 var syncTransaction = new ClusterSparqlTransaction
                 {
                     StoreId    = storeId,
                     PrevTxnId  = prevId,
                     JobId      = txn.JobId,
                     Expression = sparqlJob.Expression
                 };
                 if (!messageSink(context, syncTransaction.AsMessage()))
                 {
                     // If message sink stops accepting messages, fail the entire sync process immediately
                     return(false);
                 }
             }
         }
         else
         {
             return(false);
         }
     }
     return(true);
 }
        public Guid ProcessUpdate(ClusterSparqlTransaction txn)
        {
            if (_state != CoreState.RunningMaster)
            {
                throw new NotMasterException();
            }

            // Do some validation
            // Check store exists
            txn.JobId     = Guid.NewGuid();
            txn.PrevTxnId = _storeInfo[txn.StoreId].Queue(txn.JobId);
            _serverCore.QueueUpdate(txn.JobId, txn.StoreId, txn.Expression);
            _nodeComms.SendTransactionToSlaves(txn);
            return(txn.JobId);
        }
 public static ClusterSparqlTransaction FromMessage(Message msg)
 {
     var args = msg.Args.Split(' ');
     var txn = new ClusterSparqlTransaction
                   {
                       StoreId = args[0],
                       JobId = Guid.Parse(args[1]),
                       PrevTxnId = Guid.Parse(args[2]),
                   };
     using(var reader = msg.GetContentReader())
     {
         txn.Expression = ReadSection(reader);
     }
     return txn;
 }
Exemple #5
0
        public static ClusterSparqlTransaction FromMessage(Message msg)
        {
            var args = msg.Args.Split(' ');
            var txn  = new ClusterSparqlTransaction
            {
                StoreId   = args[0],
                JobId     = Guid.Parse(args[1]),
                PrevTxnId = Guid.Parse(args[2]),
            };

            using (var reader = msg.GetContentReader())
            {
                txn.Expression = ReadSection(reader);
            }
            return(txn);
        }
 public JobInfo ExecuteUpdate(string storeName, string updateExpression)
 {
     try
     {
         var ctxn = new ClusterSparqlTransaction()
         {
             StoreId = storeName,
             Expression = updateExpression
         };
         var jobId = NodeCore.ProcessUpdate(ctxn);
         return new JobInfo { JobId = jobId.ToString(), JobPending = true };
     }
     catch (Exception ex)
     {
         Logging.LogError(BrightstarDB.BrightstarEventId.ServerCoreException, "Error queueing sparql transaction {0} {1}", storeName, updateExpression);
         throw new BrightstarClientException("Error queueing transaction in store " + storeName + ". " + ex.Message, ex);
     }
 }
Exemple #7
0
 private bool SendTransactions(SyncContext context, Func<SyncContext, Message, bool> messageSink, IEnumerable<ITransactionInfo> transactionsToSend, string storeId,
                               Guid prevId)
 {
     foreach (var txn in transactionsToSend.Where(t => t.TransactionStatus == TransactionStatus.CompletedOk))
     {
         if (txn.TransactionType == TransactionType.UpdateTransaction)
         {
             var job = _serverCore.LoadTransaction(storeId, txn);
             if (job is UpdateTransaction)
             {
                 var updateJob = job as UpdateTransaction;
                 var syncTransaction = new ClusterUpdateTransaction
                                           {
                                               StoreId = storeId,
                                               PrevTxnId = prevId,
                                               JobId = txn.JobId,
                                               Preconditions = updateJob.Preconditions,
                                               Deletes = updateJob.DeletePatterns,
                                               Inserts = updateJob.InsertData
                                           };
                 if (!messageSink(context, syncTransaction.AsMessage()))
                 {
                     // If message sink stops accepting messages, fail the entire sync process immediately
                     return false;
                 }
             }
             else
             {
                 return false;
             }
         }
         else if (txn.TransactionType == TransactionType.SparqlUpdateTransaction)
         {
             var job = _serverCore.LoadTransaction(storeId, txn);
             if (job is SparqlUpdateJob)
             {
                 var sparqlJob = job as SparqlUpdateJob;
                 var syncTransaction = new ClusterSparqlTransaction
                                           {
                                               StoreId = storeId,
                                               PrevTxnId = prevId,
                                               JobId = txn.JobId,
                                               Expression = sparqlJob.Expression
                                           };
                 if (!messageSink(context, syncTransaction.AsMessage()))
                 {
                     // If message sink stops accepting messages, fail the entire sync process immediately
                     return false;
                 }
             }
         }
         else
         {
             return false;
         }
     }
     return true;
 }
Exemple #8
0
        public Guid ProcessUpdate(ClusterSparqlTransaction txn)
        {
            if (_state != CoreState.RunningMaster)
            {
                throw new NotMasterException();
            }

            // Do some validation
            // Check store exists
            txn.JobId = Guid.NewGuid();
            txn.PrevTxnId = _storeInfo[txn.StoreId].Queue(txn.JobId);
            _serverCore.QueueUpdate(txn.JobId, txn.StoreId, txn.Expression);
            _nodeComms.SendTransactionToSlaves(txn);
            return txn.JobId;            
        }