forked from microsoft/dicom-server
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSqlIndexDataStore.cs
96 lines (81 loc) · 5.51 KB
/
SqlIndexDataStore.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// -------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// -------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using EnsureThat;
using FellowOakDicom;
using Microsoft.Extensions.Logging;
using Microsoft.Health.Dicom.Core.Features.ExtendedQueryTag;
using Microsoft.Health.Dicom.Core.Features.Model;
using Microsoft.Health.Dicom.Core.Features.Store;
using Microsoft.Health.Dicom.SqlServer.Features.Schema;
namespace Microsoft.Health.Dicom.SqlServer.Features.Store;
internal sealed class SqlIndexDataStore : IIndexDataStore
{
private readonly VersionedCache<ISqlIndexDataStore> _cache;
private readonly ILogger<SqlIndexDataStore> _logger;
public SqlIndexDataStore(VersionedCache<ISqlIndexDataStore> cache, ILogger<SqlIndexDataStore> logger)
{
_cache = EnsureArg.IsNotNull(cache, nameof(cache));
_logger = EnsureArg.IsNotNull(logger, nameof(logger));
}
public async Task<long> BeginCreateInstanceIndexAsync(int partitionKey, DicomDataset dicomDataset, IEnumerable<QueryTag> queryTags, CancellationToken cancellationToken = default)
{
ISqlIndexDataStore store = await _cache.GetAsync(cancellationToken: cancellationToken);
return await store.BeginCreateInstanceIndexAsync(partitionKey, dicomDataset, queryTags, cancellationToken);
}
public async Task DeleteDeletedInstanceAsync(VersionedInstanceIdentifier versionedInstanceIdentifier, CancellationToken cancellationToken = default)
{
ISqlIndexDataStore store = await _cache.GetAsync(cancellationToken: cancellationToken);
await store.DeleteDeletedInstanceAsync(versionedInstanceIdentifier, cancellationToken);
}
public async Task DeleteInstanceIndexAsync(int partitionKey, string studyInstanceUid, string seriesInstanceUid, string sopInstanceUid, DateTimeOffset cleanupAfter, CancellationToken cancellationToken = default)
{
ISqlIndexDataStore store = await _cache.GetAsync(cancellationToken: cancellationToken);
await store.DeleteInstanceIndexAsync(partitionKey, studyInstanceUid, seriesInstanceUid, sopInstanceUid, cleanupAfter, cancellationToken);
}
public async Task DeleteSeriesIndexAsync(int partitionKey, string studyInstanceUid, string seriesInstanceUid, DateTimeOffset cleanupAfter, CancellationToken cancellationToken = default)
{
ISqlIndexDataStore store = await _cache.GetAsync(cancellationToken: cancellationToken);
await store.DeleteSeriesIndexAsync(partitionKey, studyInstanceUid, seriesInstanceUid, cleanupAfter, cancellationToken);
}
public async Task DeleteStudyIndexAsync(int partitionKey, string studyInstanceUid, DateTimeOffset cleanupAfter, CancellationToken cancellationToken = default)
{
ISqlIndexDataStore store = await _cache.GetAsync(cancellationToken: cancellationToken);
await store.DeleteStudyIndexAsync(partitionKey, studyInstanceUid, cleanupAfter, cancellationToken);
}
public async Task<DateTimeOffset> GetOldestDeletedAsync(CancellationToken cancellationToken = default)
{
ISqlIndexDataStore store = await _cache.GetAsync(cancellationToken: cancellationToken);
return await store.GetOldestDeletedAsync(cancellationToken);
}
public async Task<int> IncrementDeletedInstanceRetryAsync(VersionedInstanceIdentifier versionedInstanceIdentifier, DateTimeOffset cleanupAfter, CancellationToken cancellationToken = default)
{
ISqlIndexDataStore store = await _cache.GetAsync(cancellationToken: cancellationToken);
return await store.IncrementDeletedInstanceRetryAsync(versionedInstanceIdentifier, cleanupAfter, cancellationToken);
}
public async Task ReindexInstanceAsync(DicomDataset dicomDataset, long watermark, IEnumerable<QueryTag> queryTags, CancellationToken cancellationToken = default)
{
ISqlIndexDataStore store = await _cache.GetAsync(cancellationToken: cancellationToken);
await store.ReindexInstanceAsync(dicomDataset, watermark, queryTags, cancellationToken);
}
public async Task<IEnumerable<VersionedInstanceIdentifier>> RetrieveDeletedInstancesAsync(int batchSize, int maxRetries, CancellationToken cancellationToken = default)
{
ISqlIndexDataStore store = await _cache.GetAsync(cancellationToken: cancellationToken);
return await store.RetrieveDeletedInstancesAsync(batchSize, maxRetries, cancellationToken);
}
public async Task<int> RetrieveNumExhaustedDeletedInstanceAttemptsAsync(int maxNumberOfRetries, CancellationToken cancellationToken = default)
{
ISqlIndexDataStore store = await _cache.GetAsync(cancellationToken: cancellationToken);
return await store.RetrieveNumExhaustedDeletedInstanceAttemptsAsync(maxNumberOfRetries, cancellationToken);
}
public async Task EndCreateInstanceIndexAsync(int partitionKey, DicomDataset dicomDataset, long watermark, IEnumerable<QueryTag> queryTags, bool allowExpiredTags = false, bool hasFrameMetadata = false, CancellationToken cancellationToken = default)
{
ISqlIndexDataStore store = await _cache.GetAsync(cancellationToken: cancellationToken);
await store.EndCreateInstanceIndexAsync(partitionKey, dicomDataset, watermark, queryTags, allowExpiredTags, hasFrameMetadata, cancellationToken);
}
}