-
Notifications
You must be signed in to change notification settings - Fork 173
/
SqlIndexDataStore.cs
142 lines (120 loc) · 8.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// -------------------------------------------------------------------------------------------------
// 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.Common;
using Microsoft.Health.Dicom.Core.Features.ExtendedQueryTag;
using Microsoft.Health.Dicom.Core.Features.Model;
using Microsoft.Health.Dicom.Core.Features.Partitioning;
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(Partition partition, DicomDataset dicomDataset, IEnumerable<QueryTag> queryTags, CancellationToken cancellationToken = default)
{
ISqlIndexDataStore store = await _cache.GetAsync(cancellationToken: cancellationToken);
return await store.BeginCreateInstanceIndexAsync(partition, 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<IReadOnlyCollection<VersionedInstanceIdentifier>> DeleteInstanceIndexAsync(Partition partition, string studyInstanceUid, string seriesInstanceUid, string sopInstanceUid, DateTimeOffset cleanupAfter, CancellationToken cancellationToken = default)
{
ISqlIndexDataStore store = await _cache.GetAsync(cancellationToken: cancellationToken);
return await store.DeleteInstanceIndexAsync(partition, studyInstanceUid, seriesInstanceUid, sopInstanceUid, cleanupAfter, cancellationToken);
}
public async Task<IReadOnlyCollection<VersionedInstanceIdentifier>> DeleteSeriesIndexAsync(Partition partition, string studyInstanceUid, string seriesInstanceUid, DateTimeOffset cleanupAfter, CancellationToken cancellationToken = default)
{
ISqlIndexDataStore store = await _cache.GetAsync(cancellationToken: cancellationToken);
return await store.DeleteSeriesIndexAsync(partition, studyInstanceUid, seriesInstanceUid, cleanupAfter, cancellationToken);
}
public async Task<IReadOnlyCollection<VersionedInstanceIdentifier>> DeleteStudyIndexAsync(Partition partition, string studyInstanceUid, DateTimeOffset cleanupAfter, CancellationToken cancellationToken = default)
{
ISqlIndexDataStore store = await _cache.GetAsync(cancellationToken: cancellationToken);
return await store.DeleteStudyIndexAsync(partition, 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<IReadOnlyList<InstanceMetadata>> RetrieveDeletedInstancesWithPropertiesAsync(int batchSize, int maxRetries, CancellationToken cancellationToken = default)
{
ISqlIndexDataStore store = await _cache.GetAsync(cancellationToken: cancellationToken);
return await store.RetrieveDeletedInstancesWithPropertiesAsync(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, FileProperties fileProperties, bool allowExpiredTags = false, bool hasFrameMetadata = false, CancellationToken cancellationToken = default)
{
ISqlIndexDataStore store = await _cache.GetAsync(cancellationToken: cancellationToken);
await store.EndCreateInstanceIndexAsync(partitionKey, dicomDataset, watermark, queryTags, fileProperties, allowExpiredTags, hasFrameMetadata, cancellationToken);
}
public async Task<IEnumerable<InstanceMetadata>> BeginUpdateInstanceAsync(Partition partition, IReadOnlyCollection<long> versions, CancellationToken cancellationToken = default)
{
ISqlIndexDataStore store = await _cache.GetAsync(cancellationToken: cancellationToken);
return await store.BeginUpdateInstanceAsync(partition, versions, cancellationToken);
}
public async Task<IReadOnlyList<InstanceMetadata>> BeginUpdateInstancesAsync(Partition partition, string studyInstanceUid, CancellationToken cancellationToken = default)
{
ISqlIndexDataStore store = await _cache.GetAsync(cancellationToken: cancellationToken);
return await store.BeginUpdateInstancesAsync(partition, studyInstanceUid, cancellationToken);
}
public async Task EndUpdateInstanceAsync(int partitionKey, string studyInstanceUid, DicomDataset dicomDataset, IReadOnlyList<InstanceMetadata> instanceMetadataList, IEnumerable<QueryTag> queryTags, CancellationToken cancellationToken = default)
{
ISqlIndexDataStore store = await _cache.GetAsync(cancellationToken: cancellationToken);
await store.EndUpdateInstanceAsync(partitionKey, studyInstanceUid, dicomDataset, instanceMetadataList, queryTags, cancellationToken);
}
public async Task UpdateFrameDataAsync(int partitionKey, IEnumerable<long> versions, bool hasFrameMetadata, CancellationToken cancellationToken = default)
{
ISqlIndexDataStore store = await _cache.GetAsync(cancellationToken: cancellationToken);
await store.UpdateFrameDataAsync(partitionKey, versions, hasFrameMetadata, cancellationToken);
}
public async Task UpdateFilePropertiesContentLengthAsync(
IReadOnlyDictionary<long, FileProperties> filePropertiesByWatermark,
CancellationToken cancellationToken = default)
{
ISqlIndexDataStore store = await _cache.GetAsync(cancellationToken: cancellationToken);
await store.UpdateFilePropertiesContentLengthAsync(filePropertiesByWatermark, cancellationToken);
}
public async Task<IndexedFileProperties> GetIndexedFileMetricsAsync(CancellationToken cancellationToken = default)
{
ISqlIndexDataStore store = await _cache.GetAsync(cancellationToken: cancellationToken);
return await store.GetIndexedFileMetricsAsync(cancellationToken);
}
}