Skip to content

Commit

Permalink
feat: remove route key related handling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
AElfBourneShi committed Sep 20, 2024
1 parent 411fd2f commit c8c4004
Show file tree
Hide file tree
Showing 11 changed files with 735 additions and 735 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public override void ConfigureServices(ServiceConfigurationContext context)
services.AddTransient(typeof(IElasticsearchRepository<,>), typeof(ElasticsearchRepository<,>));
services.AddTransient(typeof(ICollectionNameProvider<>), typeof(ElasticsearchCollectionNameProvider<>));
services.AddSingleton(typeof (IShardingKeyProvider<>), typeof (ShardingKeyProvider<>));
services.AddSingleton(typeof(ICollectionRouteKeyProvider<>), typeof(CollectionRouteKeyProvider<>));
// services.AddSingleton(typeof(ICollectionRouteKeyProvider<>), typeof(CollectionRouteKeyProvider<>));
services.AddSingleton(typeof(IElasticsearchQueryableFactory<>), typeof(ElasticsearchQueryableFactory<>));
services.AddSingleton(typeof (IShardingCollectionTailProvider<>), typeof (ShardingCollectionTailProvider<>));
var configuration = context.Services.GetConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ public class ElasticsearchCollectionNameProvider<TEntity> : CollectionNameProvid
{
private readonly IElasticIndexService _elasticIndexService;
private readonly IShardingKeyProvider<TEntity> _shardingKeyProvider;
private readonly ICollectionRouteKeyProvider<TEntity> _collectionRouteKeyProvider;
// private readonly ICollectionRouteKeyProvider<TEntity> _collectionRouteKeyProvider;
private readonly AElfEntityMappingOptions _entityMappingOptions;
private readonly ILogger<ElasticsearchCollectionNameProvider<TEntity>> _logger;

public ElasticsearchCollectionNameProvider(IShardingKeyProvider<TEntity> shardingKeyProvider,
IElasticIndexService elasticIndexService,
ICollectionRouteKeyProvider<TEntity> collectionRouteKeyProvider,
// ICollectionRouteKeyProvider<TEntity> collectionRouteKeyProvider,
IOptions<AElfEntityMappingOptions> entityMappingOptions,
ILogger<ElasticsearchCollectionNameProvider<TEntity>> logger)
{
_elasticIndexService = elasticIndexService;
_shardingKeyProvider = shardingKeyProvider;
_collectionRouteKeyProvider = collectionRouteKeyProvider;
// _collectionRouteKeyProvider = collectionRouteKeyProvider;
_entityMappingOptions = entityMappingOptions.Value;
_logger = logger;
}
Expand All @@ -42,7 +42,8 @@ protected override async Task<List<string>> GetCollectionNameAsync(List<Collecti
var shardKeyCollectionNames = await _shardingKeyProvider.GetCollectionNameAsync(conditions);
if (shardKeyCollectionNames.IsNullOrEmpty())
{
return await _collectionRouteKeyProvider.GetCollectionNameAsync(conditions);
// return await _collectionRouteKeyProvider.GetCollectionNameAsync(conditions);
return new List<string> { GetDefaultCollectionName() };

Check warning on line 46 in src/AElf.EntityMapping.Elasticsearch/ElasticsearchCollectionNameProvider.cs

View check run for this annotation

Codecov / codecov/patch

src/AElf.EntityMapping.Elasticsearch/ElasticsearchCollectionNameProvider.cs#L46

Added line #L46 was not covered by tests
}

return shardKeyCollectionNames;
Expand Down Expand Up @@ -71,9 +72,9 @@ protected override async Task<List<string>> GetCollectionNameByEntityAsync(List<

protected override async Task<string> GetCollectionNameByIdAsync<TKey>(TKey id)
{
if (!_shardingKeyProvider.IsShardingCollection())
// if (!_shardingKeyProvider.IsShardingCollection())
return GetDefaultCollectionName();
return await _collectionRouteKeyProvider.GetCollectionNameAsync(id.ToString());
// return await _collectionRouteKeyProvider.GetCollectionNameAsync(id.ToString());
}

protected override string FormatCollectionName(string name)
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,24 @@ public async Task CreateIndexTemplateAsync(string indexTemplateName,string index
}
}

public async Task CreateCollectionRouteKeyIndexAsync(Type type, int shard = 1, int numberOfReplicas = 1)
{
var properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
foreach (var property in properties)
{
CollectionRouteKeyAttribute shardRouteAttribute = (CollectionRouteKeyAttribute)Attribute.GetCustomAttribute(property, typeof(CollectionRouteKeyAttribute));
if (shardRouteAttribute != null)
{
if (property.PropertyType != typeof(string))
{
throw new NotSupportedException(
$"{type.Name} Attribute Error! NeedShardRouteAttribute only support string type, please check field: {property.Name}");
}
var indexName = IndexNameHelper.GetCollectionRouteKeyIndexName(type, property.Name,_entityMappingOptions.CollectionPrefix);
await CreateIndexAsync(indexName, typeof(RouteKeyCollection), shard, numberOfReplicas);
}
}
}
// public async Task CreateCollectionRouteKeyIndexAsync(Type type, int shard = 1, int numberOfReplicas = 1)
// {
// var properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
// foreach (var property in properties)
// {
// CollectionRouteKeyAttribute shardRouteAttribute = (CollectionRouteKeyAttribute)Attribute.GetCustomAttribute(property, typeof(CollectionRouteKeyAttribute));
// if (shardRouteAttribute != null)
// {
// if (property.PropertyType != typeof(string))
// {
// throw new NotSupportedException(
// $"{type.Name} Attribute Error! NeedShardRouteAttribute only support string type, please check field: {property.Name}");
// }
// var indexName = IndexNameHelper.GetCollectionRouteKeyIndexName(type, property.Name,_entityMappingOptions.CollectionPrefix);
// await CreateIndexAsync(indexName, typeof(RouteKeyCollection), shard, numberOfReplicas);
// }
// }
// }

public async Task DeleteIndexAsync(string collectionName = null, CancellationToken cancellationToken = default)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,9 @@ private async Task HandleModuleAsync(Type moduleType)
await _elasticIndexService.CreateIndexTemplateAsync(indexTemplateName, indexName, t,
_elasticsearchOptions.NumberOfShards,
_elasticsearchOptions.NumberOfReplicas);
//create index marked field cache
// await _elasticIndexService.InitializeCollectionRouteKeyCacheAsync(t);
//create non shard key route index
await _elasticIndexService.CreateCollectionRouteKeyIndexAsync(t, _elasticsearchOptions.NumberOfShards,
_elasticsearchOptions.NumberOfReplicas);
// await _elasticIndexService.CreateCollectionRouteKeyIndexAsync(t, _elasticsearchOptions.NumberOfShards,
// _elasticsearchOptions.NumberOfReplicas);
await CreateShardingCollectionTailIndexAsync();
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Task CreateIndexAsync(string indexName, Type indexEntityType, int shard = 1, int
Task CreateIndexTemplateAsync(string indexTemplateName, string indexName, Type indexEntityType, int numberOfShards,
int numberOfReplicas);

Task CreateCollectionRouteKeyIndexAsync(Type indexEntityType, int numberOfShards,
int numberOfReplicas);
// Task CreateCollectionRouteKeyIndexAsync(Type indexEntityType, int numberOfShards,
// int numberOfReplicas);
Task DeleteIndexAsync(string collectionName = null, CancellationToken cancellationToken = default);
}
Loading

0 comments on commit c8c4004

Please sign in to comment.