예제 #1
0
 public ObjectLockKey(Core core, ObjectLock objectLock, UInt64 processId, LockOperation lockOperation)
 {
     this.core          = core;
     this.ProcessId     = processId;
     this.ObjectLock    = objectLock;
     this.LockOperation = lockOperation;
 }
예제 #2
0
파일: IOManager.cs 프로젝트: NTDLS/Dokdex
        public bool FileExists(Transaction transaction, string filePath, LockOperation intendedOperation)
        {
            try
            {
                string lowerFilePath = filePath.ToLower();

                var deferredExists = transaction.DeferredIOs.Collection.Values.FirstOrDefault(o => o.LowerDiskPath == lowerFilePath);
                if (deferredExists != null)
                {
                    //The file might not yet exist, but its in the cache.
                    return(true);
                }

                string cacheKey = Helpers.RemoveModFileName(lowerFilePath);
                transaction.LockFile(intendedOperation, cacheKey);

                core.Log.Trace(String.Format("IO:Exits-File:{0}->{1}", transaction.ProcessId, filePath));

                return(File.Exists(filePath));
            }
            catch (Exception ex)
            {
                core.Log.Write(String.Format("Failed to verify file for session {0}.", transaction.ProcessId), ex);
                throw;
            }
        }
예제 #3
0
파일: IOManager.cs 프로젝트: NTDLS/Dokdex
        public T InternalTrackedGet <T>(Transaction transaction, string filePath, LockOperation intendedOperation, IOFormat format)
        {
            try
            {
                string cacheKey = Helpers.RemoveModFileName(filePath.ToLower());
                transaction.LockFile(intendedOperation, cacheKey);

                if (core.settings.AllowIOCaching)
                {
                    var cachedObject = core.Cache.Get(cacheKey);

                    if (cachedObject != null)
                    {
                        core.Health.Increment(Constants.HealthCounterType.IOCacheReadHits);

                        core.Log.Trace(String.Format("IO:CacheHit:{0}->{1}", transaction.ProcessId, filePath));

                        return((T)cachedObject.Value);
                    }
                }

                core.Health.Increment(Constants.HealthCounterType.IOCacheReadMisses);

                core.Log.Trace(String.Format("IO:Read:{0}->{1}", transaction.ProcessId, filePath));

                T deserializedObject;

                if (format == IOFormat.JSON)
                {
                    string text = File.ReadAllText(filePath);
                    deserializedObject = JsonConvert.DeserializeObject <T>(text);
                }
                else if (format == IOFormat.PBuf)
                {
                    using (var file = File.OpenRead(filePath))
                    {
                        deserializedObject = ProtoBuf.Serializer.Deserialize <T>(file);
                        file.Close();
                    }
                }
                else
                {
                    throw new NotImplementedException();
                }

                if (core.settings.AllowIOCaching)
                {
                    core.Cache.Upsert(cacheKey, deserializedObject);
                    core.Health.Increment(Constants.HealthCounterType.IOCacheReadAdditions);
                }

                return(deserializedObject);
            }
            catch (Exception ex)
            {
                core.Log.Write("Failed to get JSON object.", ex);
                throw;
            }
        }
예제 #4
0
 public LockRequest(LockOperation op, LockMode mode, int timeout, ref DbEntry obj, Lock lck)
 {
     this.op      = op;
     this.mode    = mode;
     this.timeout = timeout;
     this.obj     = obj;
     this.lck     = lck;
 }
        public async Task LockFailed(int id)
        {
            Lock currLock = await GetLock(id);

            LockOperation operation = new LockOperation
            {
                Lock       = currLock,
                LockId     = id,
                CreateTime = DateTime.Now,
                State      = LockState.Failed
            };
            await _applicationDbContext.LockOperations.AddAsync(operation);

            await _applicationDbContext.SaveChangesAsync();
        }
예제 #6
0
파일: IOManager.cs 프로젝트: NTDLS/Dokdex
        public bool DirectoryExists(Transaction transaction, string diskPath, LockOperation intendedOperation)
        {
            try
            {
                string cacheKey = Helpers.RemoveModFileName(diskPath.ToLower());
                transaction.LockDirectory(intendedOperation, cacheKey);

                core.Log.Trace(String.Format("IO:Exists-Directory:{0}->{1}", transaction.ProcessId, diskPath));

                return(Directory.Exists(diskPath));
            }
            catch (Exception ex)
            {
                core.Log.Write(String.Format("Failed to verify directory for session {0}.", transaction.ProcessId), ex);
                throw;
            }
        }
예제 #7
0
        public void LockFile(LockOperation lockOperation, string diskpath)
        {
            try
            {
                diskpath = diskpath.ToLower();

                lock (HeldLockKeys)
                {
                    var lockIntention = new LockIntention()
                    {
                        Type      = LockType.File,
                        Operation = lockOperation,
                        DiskPath  = diskpath
                    };

                    core.Locking.Locks.Acquire(this, lockIntention);
                }
            }
            catch (Exception ex)
            {
                core.Log.Write("Failed to acquire file lock.", ex);
                throw;
            }
        }
예제 #8
0
 public PersistSchema GetParentMeta(Transaction transaction, PersistSchema child, LockOperation intendedOperation)
 {
     try
     {
         if (child == RootSchemaMeta)
         {
             return(null);
         }
         var segments = child.VirtualPath.Split(':').ToList();
         segments.RemoveAt(segments.Count - 1);
         string parentNs = string.Join(":", segments);
         return(VirtualPathToMeta(transaction, parentNs, intendedOperation));
     }
     catch (Exception ex)
     {
         core.Log.Write("Failed to get parent namespace meta.", ex);
         throw;
     }
 }
예제 #9
0
        public List <PersistSchema> GetChildrenMeta(Transaction transaction, PersistSchema node, LockOperation intendedOperation)
        {
            List <PersistSchema> metaList = new List <PersistSchema>();

            string namespaceCatalogDiskPath = Path.Combine(node.DiskPath, Constants.SchemaCatalogFile);

            if (core.IO.FileExists(transaction, namespaceCatalogDiskPath, intendedOperation))
            {
                var namespaceCatalog = core.IO.GetJson <PersistSchemaCatalog>(transaction, namespaceCatalogDiskPath, intendedOperation);

                foreach (var catalogItem in namespaceCatalog.Collection)
                {
                    metaList.Add(new PersistSchema()
                    {
                        DiskPath    = node.DiskPath + "\\" + catalogItem.Name,
                        Exists      = true,
                        Id          = catalogItem.Id,
                        Name        = catalogItem.Name,
                        VirtualPath = node.VirtualPath + ":" + catalogItem.Name
                    });
                }
            }

            return(metaList);
        }
예제 #10
0
        public PersistSchema VirtualPathToMeta(Transaction transaction, string schemaPath, LockOperation intendedOperation)
        {
            try
            {
                schemaPath = schemaPath.Trim(new char[] { ':' }).Trim();

                if (schemaPath == string.Empty)
                {
                    return(RootSchemaMeta);
                }
                else
                {
                    var    segments   = schemaPath.Split(':');
                    string schemaName = segments[segments.Count() - 1];

                    string namespaceDiskPath    = Path.Combine(core.Settings.DataRootPath, String.Join("\\", segments));
                    string parentSchemaDiskPath = Directory.GetParent(namespaceDiskPath).FullName;

                    string parentCatalogDiskPath = Path.Combine(parentSchemaDiskPath, Constants.SchemaCatalogFile);

                    if (core.IO.FileExists(transaction, parentCatalogDiskPath, intendedOperation) == false)
                    {
                        throw new LeafSQLInvalidSchemaException(string.Format("The schema [{0}] does not exist.", schemaPath));
                    }

                    var parentCatalog = core.IO.GetJson <PersistSchemaCatalog>(transaction,
                                                                               Path.Combine(parentSchemaDiskPath, Constants.SchemaCatalogFile), intendedOperation);

                    var namespaceMeta = parentCatalog.GetByName(schemaName);
                    if (namespaceMeta != null)
                    {
                        namespaceMeta.Name        = schemaName;
                        namespaceMeta.DiskPath    = namespaceDiskPath;
                        namespaceMeta.VirtualPath = schemaPath;
                        namespaceMeta.Exists      = true;
                    }
                    else
                    {
                        namespaceMeta = new PersistSchema()
                        {
                            Name        = schemaName,
                            DiskPath    = core.Settings.DataRootPath + "\\" + schemaPath.Replace(':', '\\'),
                            VirtualPath = schemaPath,
                            Exists      = false
                        };
                    }

                    transaction.LockDirectory(intendedOperation, namespaceMeta.DiskPath);

                    return(namespaceMeta);
                }
            }
            catch (Exception ex)
            {
                core.Log.Write("Failed to translate virtual path to namespace meta.", ex);
                throw;
            }
        }
예제 #11
0
 public LockRequest(LockOperation op, LockMode mode, int timeout, ref DbEntry obj, Lock lck) {
   this.op = op;
   this.mode = mode;
   this.timeout = timeout;
   this.obj = obj;
   this.lck = lck;
 }
예제 #12
0
파일: IOManager.cs 프로젝트: NTDLS/Dokdex
 public T GetPBuf <T>(Transaction transaction, string filePath, LockOperation intendedOperation)
 {
     return(InternalTrackedGet <T>(transaction, filePath, intendedOperation, IOFormat.PBuf));
 }
예제 #13
0
        private PersistIndexCatalog GetIndexCatalog(Transaction transaction, PersistSchema schemaMeta, LockOperation intendedOperation)
        {
            string indexCatalogDiskPath = Path.Combine(schemaMeta.DiskPath, Constants.IndexCatalogFile);
            var    indexCatalog         = core.IO.GetJson <PersistIndexCatalog>(transaction, indexCatalogDiskPath, intendedOperation);

            indexCatalog.DiskPath = indexCatalogDiskPath;

            foreach (var index in indexCatalog.Collection)
            {
                index.DiskPath = Path.Combine(schemaMeta.DiskPath, MakeIndexFileName(index.Name));
            }

            return(indexCatalog);
        }
예제 #14
0
        private PersistIndexCatalog GetIndexCatalog(Transaction transaction, string schema, LockOperation intendedOperation)
        {
            var schemaMeta = core.Schemas.VirtualPathToMeta(transaction, schema, intendedOperation);

            return(GetIndexCatalog(transaction, schemaMeta, intendedOperation));
        }