Exemplo n.º 1
0
        public Job LoadTransaction(string storeId, ITransactionInfo txn)
        {
            var transactionLog = _storeManager.GetTransactionLog(_baseLocation + "\\" + storeId);

            var jobId = Guid.NewGuid();

            switch (txn.TransactionType)
            {
            case TransactionType.ImportJob:
                var importJob = new ImportJob(jobId, null);
                importJob.ReadTransactionDataFromStream(transactionLog.GetTransactionData(txn.DataStartPosition));
                return(importJob);

            case TransactionType.UpdateTransaction:
                var updateJob = new UpdateTransaction(jobId, null);
                updateJob.ReadTransactionDataFromStream(transactionLog.GetTransactionData(txn.DataStartPosition));
                return(updateJob);

            case TransactionType.SparqlUpdateTransaction:
                var sparqlUpdateJob = new SparqlUpdateJob(jobId, null, null);
                sparqlUpdateJob.ReadTransactionDataFromStream(transactionLog.GetTransactionData(txn.DataStartPosition));
                return(sparqlUpdateJob);
            }
            return(null);
        }
Exemplo n.º 2
0
        public Guid ReExecuteTransaction(string storeId, ulong dataStartPosition, TransactionType transactionType)
        {
            var storeWorker    = GetStoreWorker(storeId);
            var transactionLog = _storeManager.GetTransactionLog(_baseLocation + "\\" + storeId);

            var jobId = Guid.NewGuid();

            switch (transactionType)
            {
            case TransactionType.ImportJob:
                var importJob = new ImportJob(jobId, storeWorker);
                importJob.ReadTransactionDataFromStream(transactionLog.GetTransactionData(dataStartPosition));
                storeWorker.QueueJob(importJob);
                break;

            case TransactionType.UpdateTransaction:
                var updateJob = new UpdateTransaction(jobId, storeWorker);
                updateJob.ReadTransactionDataFromStream(transactionLog.GetTransactionData(dataStartPosition));
                storeWorker.QueueJob(updateJob);
                break;

            case TransactionType.SparqlUpdateTransaction:
                var sparqlUpdateJob = new SparqlUpdateJob(jobId, storeWorker, null);
                sparqlUpdateJob.ReadTransactionDataFromStream(transactionLog.GetTransactionData(dataStartPosition));
                storeWorker.QueueJob(sparqlUpdateJob);
                break;
            }
            return(jobId);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Queue a txn job.
        /// </summary>
        /// <param name="preconditions">The triples that must be present for txn to succeed</param>
        /// <param name="deletePatterns"></param>
        /// <param name="insertData"></param>
        /// <param name="defaultGraphUri"></param>
        /// <param name="format"></param>
        /// <returns></returns>
        public Guid ProcessTransaction(string preconditions, string deletePatterns, string insertData, string defaultGraphUri, string format)
        {
            Logging.LogDebug("ProcessTransaction");
            var jobId = Guid.NewGuid();
            var job   = new UpdateTransaction(jobId, this, preconditions, deletePatterns, insertData, defaultGraphUri);

            QueueJob(job);
            return(jobId);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Queue a txn job.
        /// </summary>
        /// <param name="preconditions">The triples that must be present for txn to succeed</param>
        /// <param name="deletePatterns"></param>
        /// <param name="insertData"></param>
        /// <param name="format"></param>
        /// <returns></returns>
        public Guid ProcessTransaction(string preconditions, string deletePatterns, string insertData, string format)
        {
            Logging.LogInfo("ProcessTransaction");
            var jobId = Guid.NewGuid();
            var job   = new UpdateTransaction(jobId, this, preconditions, deletePatterns, insertData);

            Logging.LogDebug("Queueing Job Id {0}", jobId);
            _jobs.Enqueue(job);
            _jobExecutionStatus.TryAdd(jobId.ToString(), new JobExecutionStatus {
                JobId = jobId, JobStatus = JobStatus.Pending
            });
            return(jobId);
        }
Exemplo n.º 5
0
        public Job LoadTransaction(string storeId, ITransactionInfo txn)
        {
            var transactionLog = _storeManager.GetTransactionLog(_baseLocation + "\\" + storeId);

            var jobId = Guid.NewGuid();
            switch (txn.TransactionType)
            {
                case TransactionType.ImportJob:
                    var importJob = new ImportJob(jobId, null);
                    importJob.ReadTransactionDataFromStream(transactionLog.GetTransactionData(txn.DataStartPosition));
                    return importJob;
                case TransactionType.UpdateTransaction:
                    var updateJob = new UpdateTransaction(jobId, null);
                    updateJob.ReadTransactionDataFromStream(transactionLog.GetTransactionData(txn.DataStartPosition));
                    return updateJob;
                case TransactionType.SparqlUpdateTransaction:
                    var sparqlUpdateJob = new SparqlUpdateJob(jobId, null, null);
                    sparqlUpdateJob.ReadTransactionDataFromStream(transactionLog.GetTransactionData(txn.DataStartPosition));
                    return sparqlUpdateJob;
            }
            return null;
        }
Exemplo n.º 6
0
        public Guid ReExecuteTransaction(string storeId, ulong dataStartPosition, TransactionType transactionType)
        {
            var storeWorker = GetStoreWorker(storeId);
            var transactionLog = _storeManager.GetTransactionLog(_baseLocation + "\\" + storeId);

            var jobId = Guid.NewGuid();
            switch (transactionType)
            {
                case TransactionType.ImportJob:
                    var importJob = new ImportJob(jobId, storeWorker);
                    importJob.ReadTransactionDataFromStream(transactionLog.GetTransactionData(dataStartPosition));
                    storeWorker.QueueJob(importJob);
                    break;
                case TransactionType.UpdateTransaction:
                    var updateJob = new UpdateTransaction(jobId, storeWorker);
                    updateJob.ReadTransactionDataFromStream(transactionLog.GetTransactionData(dataStartPosition));
                    storeWorker.QueueJob(updateJob);
                    break;
                case TransactionType.SparqlUpdateTransaction:
                    var sparqlUpdateJob = new SparqlUpdateJob(jobId, storeWorker, null);
                    sparqlUpdateJob.ReadTransactionDataFromStream(transactionLog.GetTransactionData(dataStartPosition));
                    storeWorker.QueueJob(sparqlUpdateJob);
                    break;
            }
            return jobId;
        }
Exemplo n.º 7
0
        public void FindWorkingTransaction()
        {
           Store store = new Store("c:\\brightstar\\twitteringtest\\", false);
            FileStoreManager fsm = new FileStoreManager(StoreConfiguration.DefaultStoreConfiguration);
            int txnCount = 0;
            foreach (var cp in store.GetCommitPoints())
            {
                var oldStore = fsm.OpenStore("c:\\brightstar\\twitteringtest\\", cp.LocationOffset);
                try
                {
                    oldStore.ExecuteSparqlQuery(TestQuery, SparqlResultsFormat.Xml);
                    Console.WriteLine("Query worked for commit point : {0} @ {1}", cp.LocationOffset, cp.CommitTime);
                    break;
                }
                catch (Exception)
                {
                    Console.WriteLine("Query failed for commit point : {0} @ {1}", cp.LocationOffset, cp.CommitTime);
                    txnCount++;
                }
            }
            var txnLog = fsm.GetTransactionLog("c:\\brightstar\\twitteringtest");
            var txnList = txnLog.GetTransactionList();
            for(int i = 0 ; i<= txnCount;i++)
            {
                txnList.MoveNext();
                var txnInfo = txnList.Current;
                Console.WriteLine("Transaction #{0}: Start: {1}, Status: {2}, JobId: {3}", i, txnInfo.TransactionStartTime, txnInfo.TransactionStatus, txnInfo.JobId);
            }

            // Going back to last known good
            store.RevertToCommitPoint(new CommitPoint(242472899 , 0, DateTime.UtcNow, Guid.Empty));

            var toReplay = new List<ITransactionInfo>();
            txnList = txnLog.GetTransactionList();
            for(int i = 0; i < 10 ; i++)
            {
                txnList.MoveNext();
                toReplay.Add(txnList.Current);
            }

            var storeWorker = new StoreWorker("c:\\brightstar","twitteringtest");
            for(int i = 9; i >= 0; i--)
            {
                Console.WriteLine("Applying transaction : {0}", toReplay[i].JobId);
                txnLog.GetTransactionData(toReplay[i].DataStartPosition);

                var jobId = Guid.NewGuid();
                var updateJob = new UpdateTransaction(jobId, null, storeWorker);
                updateJob.ReadTransactionDataFromStream(txnLog.GetTransactionData(toReplay[i].DataStartPosition));
                updateJob.Run();

                var readStore = storeWorker.ReadStore as Store;
                var resource = readStore.Resolve(1518601251);
                Assert.IsNotNull(resource);
                try
                {
                    var query = StoreExtensions.ParseSparql(TestQuery);
                    using (var resultStream = new MemoryStream())
                    {
                        storeWorker.Query(query, SparqlResultsFormat.Xml, resultStream,
                                          new[] {Constants.DefaultGraphUri});
                    }
                    Console.WriteLine("Query succeeded");
                }
                catch(Exception ex)
                {
                    Console.WriteLine("Query failed: " + ex.Message);
                    Assert.Fail();
                }
            }
        }
Exemplo n.º 8
0
        public void TestRecoverTransactionData()
        {
            // create a store
            var sid = CreateStore();

            // initialise and start the store worker
            var storeWorker = new StoreWorker(Configuration.StoreLocation, sid);
            storeWorker.Start();

            // execute transactions
            const string data = @"<http://www.networkedplanet.com/people/gra> <http://www.networkedplanet.com/types/worksfor> <http://www.networkedplanet.com/companies/np>";

            var jobId = storeWorker.ProcessTransaction("", "", data, Constants.DefaultGraphUri, "nt");

            JobExecutionStatus jobStatus = storeWorker.GetJobStatus(jobId.ToString());
            while (jobStatus.JobStatus != JobStatus.CompletedOk)
            {
                Thread.Sleep(1000);
                jobStatus = storeWorker.GetJobStatus(jobId.ToString());
            }

            var transactionLog = storeWorker.TransactionLog;
            var transactionList = transactionLog.GetTransactionList();

            var i = 0;
            while (transactionList.MoveNext())
            {
                i++;
            }

            Assert.AreEqual(1, i);

            // now get txn data
            var txnList = storeWorker.TransactionLog.GetTransactionList();
            txnList.MoveNext();
            var tinfo = txnList.Current;
            Assert.IsNotNull(tinfo);
            Assert.AreEqual(TransactionType.UpdateTransaction, tinfo.TransactionType);
            Assert.AreEqual(TransactionStatus.CompletedOk, tinfo.TransactionStatus);
            Assert.IsTrue(tinfo.TransactionStartTime < DateTime.UtcNow);

            var job = new UpdateTransaction(Guid.NewGuid(), storeWorker);
            using (var tdStream = storeWorker.TransactionLog.GetTransactionData(tinfo.DataStartPosition))
            {
                job.ReadTransactionDataFromStream(tdStream);
            }
            Assert.IsNotNull(job);
            Assert.AreEqual(data, job.InsertData);
            
        }
Exemplo n.º 9
0
 /// <summary>
 /// Queue a txn job.
 /// </summary>
 /// <param name="preconditions">The triples that must be present for txn to succeed</param>
 /// <param name="deletePatterns"></param>
 /// <param name="insertData"></param>
 /// <param name="defaultGraphUri"></param>
 /// <param name="format"></param>
 /// <returns></returns>
 public Guid ProcessTransaction(string preconditions, string deletePatterns, string insertData, string defaultGraphUri, string format)
 {
     Logging.LogInfo("ProcessTransaction");           
     var jobId = Guid.NewGuid();
     var job = new UpdateTransaction(jobId, this, preconditions, deletePatterns, insertData, defaultGraphUri);
     Logging.LogDebug("Queueing Job Id {0}", jobId);
     _jobs.Enqueue(job);
     _jobExecutionStatus.TryAdd(jobId.ToString(), new JobExecutionStatus { JobId = jobId, JobStatus = JobStatus.Pending });
     return jobId;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Queue a txn job.
 /// </summary>
 /// <param name="preconditions">The triples that must be present for txn to succeed</param>
 /// <param name="deletePatterns"></param>
 /// <param name="insertData"></param>
 /// <param name="defaultGraphUri"></param>
 /// <param name="format"></param>
 /// <returns></returns>
 public Guid ProcessTransaction(string preconditions, string deletePatterns, string insertData, string defaultGraphUri, string format)
 {
     Logging.LogDebug("ProcessTransaction");
     var jobId = Guid.NewGuid();
     var job = new UpdateTransaction(jobId, this, preconditions, deletePatterns, insertData, defaultGraphUri);
     QueueJob(job);
     return jobId;
 }