示例#1
0
        private long GetOrAddIndex(string name, MappingDocumentType mappingDocumentType, DocumentDatabase systemDatabase)
        {
            var tries = 0;

            while (true)
            {
                try
                {
                    var key = Constants.Monitoring.Snmp.DatabaseMappingDocumentPrefix + databaseName + "/" + mappingDocumentType;

                    var mappingDocument = systemDatabase.Documents.Get(key, null) ?? new JsonDocument();

                    RavenJToken value;
                    if (mappingDocument.DataAsJson.TryGetValue(name, out value))
                    {
                        return(value.Value <int>());
                    }

                    var index = 0L;
                    systemDatabase.TransactionalStorage.Batch(actions =>
                    {
                        mappingDocument.DataAsJson[name] = index = actions.General.GetNextIdentityValue(key);
                        systemDatabase.Documents.Put(key, null, mappingDocument.DataAsJson, mappingDocument.Metadata, null);
                    });

                    return(index);
                }
                catch (Exception e)
                {
                    Exception _;
                    if (TransactionalStorageHelper.IsWriteConflict(e, out _) == false || tries >= 5)
                    {
                        throw;
                    }

                    Thread.Sleep(13);
                }
                finally
                {
                    tries++;
                }
            }
        }
示例#2
0
        private long GetOrAddIndex(string name, MappingDocumentType mappingDocumentType, DocumentDatabase systemDatabase)
        {
            var key = Constants.Monitoring.Snmp.DatabaseMappingDocumentPrefix + databaseName + "/" + mappingDocumentType;

            var mappingDocument = systemDatabase.Documents.Get(key) ?? new JsonDocument();

            RavenJToken value;

            if (mappingDocument.DataAsJson.TryGetValue(name, out value))
            {
                return(value.Value <int>());
            }

            var index = 0L;

            systemDatabase.TransactionalStorage.Batch(actions =>
            {
                mappingDocument.DataAsJson[name] = index = actions.General.GetNextIdentityValue(key);
                systemDatabase.Documents.Put(key, null, mappingDocument.DataAsJson, mappingDocument.Metadata, null);
            });

            return(index);
        }
示例#3
0
        private JsonDocument GetMappingDocument(MappingDocumentType type)
        {
            var key = Constants.Monitoring.Snmp.DatabaseMappingDocumentPrefix + databaseName + "/" + type;

            return(databaseLandlord.SystemDatabase.Documents.Get(key, null));
        }