|
@@ -100,7 +100,7 @@ namespace TEAMModelOS.SDK.DI
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
public async Task InitializeDatabase()
|
|
public async Task InitializeDatabase()
|
|
{
|
|
{
|
|
- int CollectionThroughput = 400;
|
|
|
|
|
|
+ // int CollectionThroughput = 400;
|
|
string[] DatabaseIds = BaseConfigModel.Configuration.GetSection("Azure:Cosmos:Database").Get<string[]>();
|
|
string[] DatabaseIds = BaseConfigModel.Configuration.GetSection("Azure:Cosmos:Database").Get<string[]>();
|
|
bool isMonitor = false;
|
|
bool isMonitor = false;
|
|
string leases = "leases";
|
|
string leases = "leases";
|
|
@@ -122,7 +122,7 @@ namespace TEAMModelOS.SDK.DI
|
|
{
|
|
{
|
|
string PartitionKey = AzureCosmosUtil.GetPartitionKey(type);
|
|
string PartitionKey = AzureCosmosUtil.GetPartitionKey(type);
|
|
string CollectionName = "";
|
|
string CollectionName = "";
|
|
- int RU = 0;
|
|
|
|
|
|
+ // int RU = 0;
|
|
bool cache = false;
|
|
bool cache = false;
|
|
bool monitor = false;
|
|
bool monitor = false;
|
|
IEnumerable<CosmosDBAttribute> attributes = type.GetCustomAttributes<CosmosDBAttribute>(true);
|
|
IEnumerable<CosmosDBAttribute> attributes = type.GetCustomAttributes<CosmosDBAttribute>(true);
|
|
@@ -146,25 +146,25 @@ namespace TEAMModelOS.SDK.DI
|
|
isMonitor = true;
|
|
isMonitor = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if (attributes.First<CosmosDBAttribute>().RU > 400)
|
|
|
|
- {
|
|
|
|
- RU = attributes.First<CosmosDBAttribute>().RU;
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- RU = CollectionThroughput;
|
|
|
|
- }
|
|
|
|
|
|
+ //if (attributes.First<CosmosDBAttribute>().RU > 400)
|
|
|
|
+ //{
|
|
|
|
+ // RU = attributes.First<CosmosDBAttribute>().RU;
|
|
|
|
+ //}
|
|
|
|
+ //else
|
|
|
|
+ //{
|
|
|
|
+ // RU = CollectionThroughput;
|
|
|
|
+ //}
|
|
//如果表存在于数据则检查RU是否变动,如果不存在则执行创建DocumentCollection
|
|
//如果表存在于数据则检查RU是否变动,如果不存在则执行创建DocumentCollection
|
|
if (CosmosDict.nameCosmos.TryGetValue(CollectionName, out AzureCosmosModel AzureCosmosModel))
|
|
if (CosmosDict.nameCosmos.TryGetValue(CollectionName, out AzureCosmosModel AzureCosmosModel))
|
|
{ //更新RU
|
|
{ //更新RU
|
|
|
|
|
|
AzureCosmosModel.cache = cache;
|
|
AzureCosmosModel.cache = cache;
|
|
CosmosContainer container = GetCosmosClient().GetDatabase(attributes.First().Database).GetContainer(AzureCosmosModel.container.Id);
|
|
CosmosContainer container = GetCosmosClient().GetDatabase(attributes.First().Database).GetContainer(AzureCosmosModel.container.Id);
|
|
- int? throughputResponse = await container.ReadThroughputAsync();
|
|
|
|
- if (throughputResponse < RU)
|
|
|
|
- {
|
|
|
|
- await GetCosmosClient().GetDatabase(attributes.First().Database).GetContainer(AzureCosmosModel.container.Id).ReplaceThroughputAsync(RU);
|
|
|
|
- }
|
|
|
|
|
|
+ //int? throughputResponse = await container.ReadThroughputAsync();
|
|
|
|
+ //if (throughputResponse < RU)
|
|
|
|
+ //{
|
|
|
|
+ // await GetCosmosClient().GetDatabase(attributes.First().Database).GetContainer(AzureCosmosModel.container.Id).ReplaceThroughputAsync(RU);
|
|
|
|
+ //}
|
|
AzureCosmosModel cosmos = new AzureCosmosModel { container = container, cache = cache, monitor = monitor, type = type, partitionKey = PartitionKey };
|
|
AzureCosmosModel cosmos = new AzureCosmosModel { container = container, cache = cache, monitor = monitor, type = type, partitionKey = PartitionKey };
|
|
CosmosDict.nameCosmos[CollectionName] = cosmos;
|
|
CosmosDict.nameCosmos[CollectionName] = cosmos;
|
|
CosmosDict.typeCosmos.Add(type.Name, cosmos);
|
|
CosmosDict.typeCosmos.Add(type.Name, cosmos);
|
|
@@ -176,12 +176,12 @@ namespace TEAMModelOS.SDK.DI
|
|
{
|
|
{
|
|
containerProperties.PartitionKeyPath = "/" + PartitionKey;
|
|
containerProperties.PartitionKeyPath = "/" + PartitionKey;
|
|
}
|
|
}
|
|
- if (RU > CollectionThroughput)
|
|
|
|
- {
|
|
|
|
- CollectionThroughput = RU;
|
|
|
|
- }
|
|
|
|
|
|
+ //if (RU > CollectionThroughput)
|
|
|
|
+ //{
|
|
|
|
+ // CollectionThroughput = RU;
|
|
|
|
+ //}
|
|
CosmosDatabase database = GetCosmosClient().GetDatabase(attributes.First().Database);
|
|
CosmosDatabase database = GetCosmosClient().GetDatabase(attributes.First().Database);
|
|
- CosmosContainer containerWithConsistentIndexing =await database.CreateContainerIfNotExistsAsync(containerProperties, throughput: CollectionThroughput);
|
|
|
|
|
|
+ CosmosContainer containerWithConsistentIndexing =await database.CreateContainerIfNotExistsAsync(containerProperties);
|
|
AzureCosmosModel cosmos = new AzureCosmosModel { container = containerWithConsistentIndexing, cache = cache, monitor = monitor, type = type, partitionKey = PartitionKey,database=database };
|
|
AzureCosmosModel cosmos = new AzureCosmosModel { container = containerWithConsistentIndexing, cache = cache, monitor = monitor, type = type, partitionKey = PartitionKey,database=database };
|
|
CosmosDict.nameCosmos[CollectionName] = cosmos;
|
|
CosmosDict.nameCosmos[CollectionName] = cosmos;
|
|
CosmosDict.typeCosmos.Add(type.Name, cosmos);
|
|
CosmosDict.typeCosmos.Add(type.Name, cosmos);
|
|
@@ -195,7 +195,7 @@ namespace TEAMModelOS.SDK.DI
|
|
{
|
|
{
|
|
CosmosDatabase database = GetCosmosClient().GetDatabase(DatabaseId);
|
|
CosmosDatabase database = GetCosmosClient().GetDatabase(DatabaseId);
|
|
ContainerProperties leaseProperties = new ContainerProperties { Id = leases, PartitionKeyPath = "/id", DefaultTimeToLive = -1 };
|
|
ContainerProperties leaseProperties = new ContainerProperties { Id = leases, PartitionKeyPath = "/id", DefaultTimeToLive = -1 };
|
|
- CosmosContainer leaseContainer = await database.CreateContainerIfNotExistsAsync(leaseProperties, throughput: CollectionThroughput);
|
|
|
|
|
|
+ CosmosContainer leaseContainer = await database.CreateContainerIfNotExistsAsync(leaseProperties);
|
|
CosmosDict.nameCosmos.TryAdd(leases, new AzureCosmosModel { container = leaseContainer, cache = false, monitor = false, partitionKey = "/id", database = database });
|
|
CosmosDict.nameCosmos.TryAdd(leases, new AzureCosmosModel { container = leaseContainer, cache = false, monitor = false, partitionKey = "/id", database = database });
|
|
}
|
|
}
|
|
}
|
|
}
|