Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v1.2.0 #34

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ 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(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,16 @@
{
private readonly IElasticIndexService _elasticIndexService;
private readonly IShardingKeyProvider<TEntity> _shardingKeyProvider;
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,
IOptions<AElfEntityMappingOptions> entityMappingOptions,
ILogger<ElasticsearchCollectionNameProvider<TEntity>> logger)
{
_elasticIndexService = elasticIndexService;
_shardingKeyProvider = shardingKeyProvider;
_collectionRouteKeyProvider = collectionRouteKeyProvider;
_entityMappingOptions = entityMappingOptions.Value;
_logger = logger;
}
Expand All @@ -42,7 +39,7 @@
var shardKeyCollectionNames = await _shardingKeyProvider.GetCollectionNameAsync(conditions);
if (shardKeyCollectionNames.IsNullOrEmpty())
{
return await _collectionRouteKeyProvider.GetCollectionNameAsync(conditions);
return new List<string> { GetDefaultCollectionName() };

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L42 was not covered by tests
}

return shardKeyCollectionNames;
Expand Down Expand Up @@ -71,9 +68,7 @@

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

protected override string FormatCollectionName(string name)
Expand Down
7 changes: 0 additions & 7 deletions src/AElf.EntityMapping.Elasticsearch/IndexNameHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,4 @@ public static string GetDefaultFullIndexName(Type type,string collectionPrefix)
: $"{collectionPrefix.ToLower()}.{GetDefaultIndexName(type)}";
return fullIndexName;
}
public static string GetCollectionRouteKeyIndexName(Type type, string fieldName,string collectionPrefix)
{
var routeIndexName= collectionPrefix.IsNullOrWhiteSpace()
? $"route.{type.Name.ToLower()}.{fieldName.ToLower()}"
: $"{collectionPrefix.ToLower()}.route.{type.Name.ToLower()}.{fieldName.ToLower()}";
return routeIndexName;
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -127,25 +127,6 @@ public async Task CreateIndexTemplateAsync(string indexTemplateName,string index
_logger.LogInformation("Index template {indexTemplateName} created successfully", indexTemplateName);
}
}

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,6 @@ 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 CreateShardingCollectionTailIndexAsync();
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@ 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 DeleteIndexAsync(string collectionName = null, CancellationToken cancellationToken = default);
}
Loading