-
Notifications
You must be signed in to change notification settings - Fork 217
Expand file tree
/
Copy pathstores.rs
More file actions
1619 lines (1470 loc) · 60.1 KB
/
stores.rs
File metadata and controls
1619 lines (1470 loc) · 60.1 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2024 The NativeLink Authors. All rights reserved.
//
// Licensed under the Functional Source License, Version 1.1, Apache 2.0 Future License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// See LICENSE file for details
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use core::time::Duration;
use std::collections::HashMap;
use std::sync::Arc;
use rand::Rng;
#[cfg(feature = "dev-schema")]
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use crate::serde_utils::{
convert_boolean_with_shellexpand, convert_data_size_with_shellexpand,
convert_duration_with_shellexpand, convert_numeric_with_shellexpand,
convert_optional_data_size_with_shellexpand, convert_optional_numeric_with_shellexpand,
convert_optional_string_with_shellexpand, convert_string_with_shellexpand,
convert_vec_string_with_shellexpand,
};
/// Name of the store. This type will be used when referencing a store
/// in the `CasConfig::stores`'s map key.
pub type StoreRefName = String;
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "dev-schema", derive(JsonSchema))]
pub enum ConfigDigestHashFunction {
/// Use the sha256 hash function.
/// <https://en.wikipedia.org/wiki/SHA-2>
Sha256,
/// Use the blake3 hash function.
/// <https://en.wikipedia.org/wiki/BLAKE_(hash_function)>
Blake3,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "dev-schema", derive(JsonSchema))]
pub enum StoreSpec {
/// Memory store will store all data in a hashmap in memory.
///
/// **Example JSON Config:**
/// ```json
/// "memory": {
/// "eviction_policy": {
/// "max_bytes": "10mb",
/// }
/// }
/// ```
///
Memory(MemorySpec),
/// A generic blob store that will store files on the cloud
/// provider. This configuration will never delete files, so you are
/// responsible for purging old files in other ways.
/// It supports the following backends:
///
/// 1. **Amazon S3:**
/// S3 store will use Amazon's S3 service as a backend to store
/// the files. This configuration can be used to share files
/// across multiple instances. Uses system certificates for TLS
/// verification via `rustls-platform-verifier`.
///
/// **Example JSON Config:**
/// ```json
/// "experimental_cloud_object_store": {
/// "provider": "aws",
/// "region": "eu-north-1",
/// "bucket": "crossplane-bucket-af79aeca9",
/// "key_prefix": "test-prefix-index/",
/// "retry": {
/// "max_retries": 6,
/// "delay": 0.3,
/// "jitter": 0.5
/// },
/// "multipart_max_concurrent_uploads": 10
/// }
/// ```
///
/// 2. **Google Cloud Storage:**
/// GCS store uses Google's GCS service as a backend to store
/// the files. This configuration can be used to share files
/// across multiple instances.
///
/// **Example JSON Config:**
/// ```json
/// "experimental_cloud_object_store": {
/// "provider": "gcs",
/// "bucket": "test-bucket",
/// "key_prefix": "test-prefix-index/",
/// "retry": {
/// "max_retries": 6,
/// "delay": 0.3,
/// "jitter": 0.5
/// },
/// "multipart_max_concurrent_uploads": 10
/// }
/// ```
///
/// 3. **Azure Blob Store:**
/// Azure Blob store will use Microsoft's Azure Blob service as a
/// backend to store the files. This configuration can be used to
/// share files across multiple instances.
///
/// **Example JSON Config:**
/// ```json
/// "experimental_cloud_object_store": {
/// "provider": "azure",
/// "account_name": "cloudshell1393657559",
/// "container": "simple-test-container",
/// "key_prefix": "folder/",
/// "retry": {
/// "max_retries": 6,
/// "delay": 0.3,
/// "jitter": 0.5
/// },
/// "multipart_max_concurrent_uploads": 10
/// }
/// ```
///
/// 4. **`NetApp` ONTAP S3**
/// `NetApp` ONTAP S3 store will use ONTAP's S3-compatible storage as a backend
/// to store files. This store is specifically configured for ONTAP's S3 requirements
/// including custom TLS configuration, credentials management, and proper vserver
/// configuration.
///
/// This store uses AWS environment variables for credentials:
/// - `AWS_ACCESS_KEY_ID`
/// - `AWS_SECRET_ACCESS_KEY`
/// - `AWS_DEFAULT_REGION`
///
/// **Example JSON Config:**
/// ```json
/// "experimental_cloud_object_store": {
/// "provider": "ontap",
/// "endpoint": "https://ontap-s3-endpoint:443",
/// "vserver_name": "your-vserver",
/// "bucket": "your-bucket",
/// "root_certificates": "/path/to/certs.pem", // Optional
/// "key_prefix": "test-prefix/", // Optional
/// "retry": {
/// "max_retries": 6,
/// "delay": 0.3,
/// "jitter": 0.5
/// },
/// "multipart_max_concurrent_uploads": 10
/// }
/// ```
ExperimentalCloudObjectStore(ExperimentalCloudObjectSpec),
/// ONTAP S3 Existence Cache provides a caching layer on top of the ONTAP S3 store
/// to optimize repeated existence checks. It maintains an in-memory cache of object
/// digests and periodically syncs this cache to disk for persistence.
///
/// The cache helps reduce latency for repeated calls to check object existence,
/// while still ensuring eventual consistency with the underlying ONTAP S3 store.
///
/// Example JSON Config:
/// ```json
/// "ontap_s3_existence_cache": {
/// "index_path": "/path/to/cache/index.json",
/// "sync_interval_seconds": 300,
/// "backend": {
/// "endpoint": "https://ontap-s3-endpoint:443",
/// "vserver_name": "your-vserver",
/// "bucket": "your-bucket",
/// "key_prefix": "test-prefix/"
/// }
/// }
/// ```
///
OntapS3ExistenceCache(Box<OntapS3ExistenceCacheSpec>),
/// Verify store is used to apply verifications to an underlying
/// store implementation. It is strongly encouraged to validate
/// as much data as you can before accepting data from a client,
/// failing to do so may cause the data in the store to be
/// populated with invalid data causing all kinds of problems.
///
/// The suggested configuration is to have the CAS validate the
/// hash and size and the AC validate nothing.
///
/// **Example JSON Config:**
/// ```json
/// "verify": {
/// "backend": {
/// "memory": {
/// "eviction_policy": {
/// "max_bytes": "500mb"
/// }
/// },
/// },
/// "verify_size": true,
/// "verify_hash": true
/// }
/// ```
///
Verify(Box<VerifySpec>),
/// Completeness checking store verifies if the
/// output files & folders exist in the CAS before forwarding
/// the request to the underlying store.
/// Note: This store should only be used on AC stores.
///
/// **Example JSON Config:**
/// ```json
/// "completeness_checking": {
/// "backend": {
/// "filesystem": {
/// "content_path": "~/.cache/nativelink/content_path-ac",
/// "temp_path": "~/.cache/nativelink/tmp_path-ac",
/// "eviction_policy": {
/// "max_bytes": "500mb",
/// }
/// }
/// },
/// "cas_store": {
/// "ref_store": {
/// "name": "CAS_MAIN_STORE"
/// }
/// }
/// }
/// ```
///
CompletenessChecking(Box<CompletenessCheckingSpec>),
/// A compression store that will compress the data inbound and
/// outbound. There will be a non-trivial cost to compress and
/// decompress the data, but in many cases if the final store is
/// a store that requires network transport and/or storage space
/// is a concern it is often faster and more efficient to use this
/// store before those stores.
///
/// **Example JSON Config:**
/// ```json
/// "compression": {
/// "compression_algorithm": {
/// "lz4": {}
/// },
/// "backend": {
/// "filesystem": {
/// "content_path": "/tmp/nativelink/data/content_path-cas",
/// "temp_path": "/tmp/nativelink/data/tmp_path-cas",
/// "eviction_policy": {
/// "max_bytes": "2gb",
/// }
/// }
/// }
/// }
/// ```
///
Compression(Box<CompressionSpec>),
/// A dedup store will take the inputs and run a rolling hash
/// algorithm on them to slice the input into smaller parts then
/// run a sha256 algorithm on the slice and if the object doesn't
/// already exist, upload the slice to the `content_store` using
/// a new digest of just the slice. Once all parts exist, an
/// Action-Cache-like digest will be built and uploaded to the
/// `index_store` which will contain a reference to each
/// chunk/digest of the uploaded file. Downloading a request will
/// first grab the index from the `index_store`, and forward the
/// download content of each chunk as if it were one file.
///
/// This store is exceptionally good when the following conditions
/// are met:
/// * Content is mostly the same (inserts, updates, deletes are ok)
/// * Content is not compressed or encrypted
/// * Uploading or downloading from `content_store` is the bottleneck.
///
/// Note: This store pairs well when used with `CompressionSpec` as
/// the `content_store`, but never put `DedupSpec` as the backend of
/// `CompressionSpec` as it will negate all the gains.
///
/// Note: When running `.has()` on this store, it will only check
/// to see if the entry exists in the `index_store` and not check
/// if the individual chunks exist in the `content_store`.
///
/// **Example JSON Config:**
/// ```json
/// "dedup": {
/// "index_store": {
/// "memory": {
/// "eviction_policy": {
/// "max_bytes": "1GB",
/// }
/// }
/// },
/// "content_store": {
/// "compression": {
/// "compression_algorithm": {
/// "lz4": {}
/// },
/// "backend": {
/// "fast_slow": {
/// "fast": {
/// "memory": {
/// "eviction_policy": {
/// "max_bytes": "500MB",
/// }
/// }
/// },
/// "slow": {
/// "filesystem": {
/// "content_path": "/tmp/nativelink/data/content_path-content",
/// "temp_path": "/tmp/nativelink/data/tmp_path-content",
/// "eviction_policy": {
/// "max_bytes": "2gb"
/// }
/// }
/// }
/// }
/// }
/// }
/// }
/// }
/// ```
///
Dedup(Box<DedupSpec>),
/// Existence store will wrap around another store and cache calls
/// to has so that subsequent `has_with_results` calls will be
/// faster. This is useful for cases when you have a store that
/// is slow to respond to has calls.
/// Note: This store should only be used on CAS stores.
///
/// **Example JSON Config:**
/// ```json
/// "existence_cache": {
/// "backend": {
/// "memory": {
/// "eviction_policy": {
/// "max_bytes": "500mb",
/// }
/// }
/// },
/// // Note this is the existence store policy, not the backend policy
/// "eviction_policy": {
/// "max_seconds": 100,
/// }
/// }
/// ```
///
ExistenceCache(Box<ExistenceCacheSpec>),
/// `FastSlow` store will first try to fetch the data from the `fast`
/// store and then if it does not exist try the `slow` store.
/// When the object does exist in the `slow` store, it will copy
/// the data to the `fast` store while returning the data.
/// This store should be thought of as a store that "buffers"
/// the data to the `fast` store.
/// On uploads it will mirror data to both `fast` and `slow` stores.
///
/// WARNING: If you need data to always exist in the `slow` store
/// for something like remote execution, be careful because this
/// store will never check to see if the objects exist in the
/// `slow` store if it exists in the `fast` store (ie: it assumes
/// that if an object exists in the `fast` store it will exist in
/// the `slow` store).
///
/// ***Example JSON Config:***
/// ```json
/// "fast_slow": {
/// "fast": {
/// "filesystem": {
/// "content_path": "/tmp/nativelink/data/content_path-index",
/// "temp_path": "/tmp/nativelink/data/tmp_path-index",
/// "eviction_policy": {
/// "max_bytes": "500mb",
/// }
/// }
/// },
/// "slow": {
/// "filesystem": {
/// "content_path": "/tmp/nativelink/data/content_path-index",
/// "temp_path": "/tmp/nativelink/data/tmp_path-index",
/// "eviction_policy": {
/// "max_bytes": "500mb",
/// }
/// }
/// }
/// }
/// ```
///
FastSlow(Box<FastSlowSpec>),
/// Shards the data to multiple stores. This is useful for cases
/// when you want to distribute the load across multiple stores.
/// The digest hash is used to determine which store to send the
/// data to.
///
/// **Example JSON Config:**
/// ```json
/// "shard": {
/// "stores": [
/// {
/// "store": {
/// "memory": {
/// "eviction_policy": {
/// "max_bytes": "10mb"
/// },
/// },
/// },
/// "weight": 1
/// }]
/// }
/// ```
///
Shard(ShardSpec),
/// Stores the data on the filesystem. This store is designed for
/// local persistent storage. Restarts of this program should restore
/// the previous state, meaning anything uploaded will be persistent
/// as long as the filesystem integrity holds.
///
/// **Example JSON Config:**
/// ```json
/// "filesystem": {
/// "content_path": "/tmp/nativelink/data-worker-test/content_path-cas",
/// "temp_path": "/tmp/nativelink/data-worker-test/tmp_path-cas",
/// "eviction_policy": {
/// "max_bytes": "10gb",
/// }
/// }
/// ```
///
Filesystem(FilesystemSpec),
/// Store used to reference a store in the root store manager.
/// This is useful for cases when you want to share a store in different
/// nested stores. Example, you may want to share the same memory store
/// used for the action cache, but use a `FastSlowSpec` and have the fast
/// store also share the memory store for efficiency.
///
/// **Example JSON Config:**
/// ```json
/// "ref_store": {
/// "name": "FS_CONTENT_STORE"
/// }
/// ```
///
RefStore(RefSpec),
/// Uses the size field of the digest to separate which store to send the
/// data. This is useful for cases when you'd like to put small objects
/// in one store and large objects in another store. This should only be
/// used if the size field is the real size of the content, in other
/// words, don't use on AC (Action Cache) stores. Any store where you can
/// safely use `VerifySpec.verify_size = true`, this store should be safe
/// to use (ie: CAS stores).
///
/// **Example JSON Config:**
/// ```json
/// "size_partitioning": {
/// "size": "128mib",
/// "lower_store": {
/// "memory": {
/// "eviction_policy": {
/// "max_bytes": "${NATIVELINK_CAS_MEMORY_CONTENT_LIMIT:-100mb}"
/// }
/// }
/// },
/// "upper_store": {
/// /// This store discards data larger than 128mib.
/// "noop": {}
/// }
/// }
/// ```
///
SizePartitioning(Box<SizePartitioningSpec>),
/// This store will pass-through calls to another GRPC store. This store
/// is not designed to be used as a sub-store of another store, but it
/// does satisfy the interface and will likely work.
///
/// One major GOTCHA is that some stores use a special function on this
/// store to get the size of the underlying object, which is only reliable
/// when this store is serving the a CAS store, not an AC store. If using
/// this store directly without being a child of any store there are no
/// side effects and is the most efficient way to use it.
///
/// **Example JSON Config:**
/// ```json
/// "grpc": {
/// "instance_name": "main",
/// "endpoints": [
/// {"address": "grpc://${CAS_ENDPOINT:-127.0.0.1}:50051"}
/// ],
/// "connections_per_endpoint": "5",
/// "rpc_timeout_s": "5m",
/// "store_type": "ac",
/// // Static headers attached to every outgoing request to the upstream
/// // remote cache. Useful for fixed service-account credentials.
/// "headers": {
/// "authorization": "Bearer my-static-token"
/// },
/// // Header names to copy from the inbound client request and forward to
/// // the upstream remote cache. Use this to pass through dynamic
/// // credentials such as a JWT sent by the build client.
/// "forward_headers": ["authorization", "x-custom-token"]
/// }
/// ```
///
Grpc(GrpcSpec),
/// Stores data in any stores compatible with Redis APIs.
///
/// Pairs well with `SizePartitioning` and/or `FastSlow` stores.
/// Ideal for accepting small object sizes as most redis store
/// services have a max file upload of between 256Mb-512Mb.
///
/// **Example JSON Config:**
/// ```json
/// "redis_store": {
/// "addresses": [
/// "redis://127.0.0.1:6379/",
/// ],
/// "max_client_permits": 1000,
/// }
/// ```
///
RedisStore(RedisSpec),
/// Noop store is a store that sends streams into the void and all data
/// retrieval will return 404 (`NotFound`). This can be useful for cases
/// where you may need to partition your data and part of your data needs
/// to be discarded.
///
/// **Example JSON Config:**
/// ```json
/// "noop": {}
/// ```
///
Noop(NoopSpec),
/// Experimental `MongoDB` store implementation.
///
/// This store uses `MongoDB` as a backend for storing data. It supports
/// both CAS (Content Addressable Storage) and scheduler data with
/// optional change streams for real-time updates.
///
/// **Example JSON Config:**
/// ```json
/// "experimental_mongo": {
/// "connection_string": "mongodb://localhost:27017",
/// "database": "nativelink",
/// "cas_collection": "cas",
/// "key_prefix": "cas:",
/// "read_chunk_size": 65536,
/// "max_concurrent_uploads": 10,
/// "enable_change_streams": false,
/// "max_requests": "100"
/// }
/// ```
///
ExperimentalMongo(ExperimentalMongoSpec),
}
/// Configuration for an individual shard of the store.
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(deny_unknown_fields)]
#[cfg_attr(feature = "dev-schema", derive(JsonSchema))]
pub struct ShardConfig {
/// Store to shard the data to.
pub store: StoreSpec,
/// The weight of the store. This is used to determine how much data
/// should be sent to the store. The actual percentage is the sum of
/// all the store's weights divided by the individual store's weight.
///
/// Default: 1
#[serde(deserialize_with = "convert_optional_numeric_with_shellexpand")]
pub weight: Option<u32>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(deny_unknown_fields)]
#[cfg_attr(feature = "dev-schema", derive(JsonSchema))]
pub struct ShardSpec {
/// Stores to shard the data to.
pub stores: Vec<ShardConfig>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(deny_unknown_fields)]
#[cfg_attr(feature = "dev-schema", derive(JsonSchema))]
pub struct SizePartitioningSpec {
/// Size to partition the data on.
#[serde(deserialize_with = "convert_data_size_with_shellexpand")]
pub size: u64,
/// Store to send data when object is < (less than) size.
pub lower_store: StoreSpec,
/// Store to send data when object is >= (less than eq) size.
pub upper_store: StoreSpec,
}
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
#[serde(deny_unknown_fields)]
#[cfg_attr(feature = "dev-schema", derive(JsonSchema))]
pub struct RefSpec {
/// Name of the store under the root "stores" config object.
#[serde(deserialize_with = "convert_string_with_shellexpand")]
pub name: String,
}
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
#[serde(deny_unknown_fields)]
#[cfg_attr(feature = "dev-schema", derive(JsonSchema))]
pub struct FilesystemSpec {
/// Path on the system where to store the actual content. This is where
/// the bulk of the data will be placed.
/// On service bootup this folder will be scanned and all files will be
/// added to the cache. In the event one of the files doesn't match the
/// criteria, the file will be deleted.
#[serde(deserialize_with = "convert_string_with_shellexpand")]
pub content_path: String,
/// A temporary location of where files that are being uploaded or
/// deleted will be placed while the content cannot be guaranteed to be
/// accurate. This location must be on the same block device as
/// `content_path` so atomic moves can happen (ie: move without copy).
/// All files in this folder will be deleted on every startup.
#[serde(deserialize_with = "convert_string_with_shellexpand")]
pub temp_path: String,
/// Buffer size to use when reading files. Generally this should be left
/// to the default value except for testing.
/// Default: 32k.
#[serde(default, deserialize_with = "convert_data_size_with_shellexpand")]
pub read_buffer_size: u32,
/// Policy used to evict items out of the store. Failure to set this
/// value will cause items to never be removed from the store causing
/// infinite memory usage.
pub eviction_policy: Option<EvictionPolicy>,
/// The block size of the filesystem for the running machine
/// value is used to determine an entry's actual size on disk consumed
/// For a 4KB block size filesystem, a 1B file actually consumes 4KB
/// Default: 4096
#[serde(default, deserialize_with = "convert_data_size_with_shellexpand")]
pub block_size: u64,
/// Maximum number of concurrent write operations allowed.
/// Each write involves streaming data to a temp file and calling `sync_all()`,
/// which can saturate disk I/O when many writes happen simultaneously.
/// Limiting concurrency prevents disk saturation from blocking the async
/// runtime.
/// A value of 0 means unlimited (no concurrency limit).
/// Default: 0
#[serde(default, deserialize_with = "convert_numeric_with_shellexpand")]
pub max_concurrent_writes: usize,
}
// NetApp ONTAP S3 Spec
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
#[serde(deny_unknown_fields)]
#[cfg_attr(feature = "dev-schema", derive(JsonSchema))]
pub struct ExperimentalOntapS3Spec {
#[serde(deserialize_with = "convert_string_with_shellexpand")]
pub endpoint: String,
#[serde(deserialize_with = "convert_string_with_shellexpand")]
pub vserver_name: String,
#[serde(deserialize_with = "convert_string_with_shellexpand")]
pub bucket: String,
#[serde(default, deserialize_with = "convert_optional_string_with_shellexpand")]
pub root_certificates: Option<String>,
/// Common retry and upload configuration
#[serde(flatten)]
pub common: CommonObjectSpec,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(deny_unknown_fields)]
#[cfg_attr(feature = "dev-schema", derive(JsonSchema))]
pub struct OntapS3ExistenceCacheSpec {
#[serde(deserialize_with = "convert_string_with_shellexpand")]
pub index_path: String,
#[serde(deserialize_with = "convert_numeric_with_shellexpand")]
pub sync_interval_seconds: u32,
pub backend: Box<ExperimentalOntapS3Spec>,
}
#[derive(Serialize, Deserialize, Default, Debug, Clone, Copy, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "dev-schema", derive(JsonSchema))]
pub enum StoreDirection {
/// The store operates normally and all get and put operations are
/// handled by it.
#[default]
Both,
/// Update operations will cause persistence to this store, but Get
/// operations will be ignored.
/// This only makes sense on the fast store as the slow store will
/// never get written to on Get anyway.
Update,
/// Get operations will cause persistence to this store, but Update
/// operations will be ignored.
Get,
/// Operate as a read only store, only really makes sense if there's
/// another way to write to it.
ReadOnly,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(deny_unknown_fields)]
#[cfg_attr(feature = "dev-schema", derive(JsonSchema))]
pub struct FastSlowSpec {
/// Fast store that will be attempted to be contacted before reaching
/// out to the `slow` store.
pub fast: StoreSpec,
/// How to handle the fast store. This can be useful to set to Get for
/// worker nodes such that results are persisted to the slow store only.
#[serde(default)]
pub fast_direction: StoreDirection,
/// If the object does not exist in the `fast` store it will try to
/// get it from this store.
pub slow: StoreSpec,
/// How to handle the slow store. This can be useful if creating a diode
/// and you wish to have an upstream read only store.
#[serde(default)]
pub slow_direction: StoreDirection,
/// Reads of blobs at or above this size bypass the populating-digests
/// dedup map and stream directly from the slow store, without
/// populating the fast tier.
///
/// Rationale: the leader/follower dedup is a win for blobs whose
/// transfer time is short relative to `LEADER_WAIT_TIMEOUT` — one
/// slow-store fetch fills the fast cache, subsequent readers serve
/// from fast. For multi-GB blobs (typically container layers) the
/// leader's transfer takes minutes; every concurrent follower hits
/// the timeout, falls through to the slow store anyway, and the
/// fast cache is then evicted aggressively to make room for the
/// huge blob — pushing out smaller, more-frequently-read entries.
/// Bypassing dedup for huge blobs avoids both pathologies.
///
/// Set to 0 (default) to use the built-in default of 256 MiB. Set
/// to a very large value (e.g. `u64::MAX`) to disable the bypass
/// and always use dedup regardless of size.
#[serde(default, deserialize_with = "convert_data_size_with_shellexpand")]
pub bypass_dedup_threshold_bytes: u64,
}
#[derive(Serialize, Deserialize, Debug, Default, Clone, Copy)]
#[serde(deny_unknown_fields)]
#[cfg_attr(feature = "dev-schema", derive(JsonSchema))]
pub struct MemorySpec {
/// Policy used to evict items out of the store. Failure to set this
/// value will cause items to never be removed from the store causing
/// infinite memory usage.
pub eviction_policy: Option<EvictionPolicy>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(deny_unknown_fields)]
#[cfg_attr(feature = "dev-schema", derive(JsonSchema))]
pub struct DedupSpec {
/// Store used to store the index of each dedup slice. This store
/// should generally be fast and small.
pub index_store: StoreSpec,
/// The store where the individual chunks will be uploaded. This
/// store should generally be the slower & larger store.
pub content_store: StoreSpec,
/// Minimum size that a chunk will be when slicing up the content.
/// Note: This setting can be increased to improve performance
/// because it will actually not check this number of bytes when
/// deciding where to partition the data.
///
/// Default: 65536 (64k)
#[serde(default, deserialize_with = "convert_data_size_with_shellexpand")]
pub min_size: u32,
/// A best-effort attempt will be made to keep the average size
/// of the chunks to this number. It is not a guarantee, but a
/// slight attempt will be made.
///
/// This value will also be about the threshold used to determine
/// if we should even attempt to dedup the entry or just forward
/// it directly to the `content_store` without an index. The actual
/// value will be about `normal_size * 1.3` due to implementation
/// details.
///
/// Default: 262144 (256k)
#[serde(default, deserialize_with = "convert_data_size_with_shellexpand")]
pub normal_size: u32,
/// Maximum size a chunk is allowed to be.
///
/// Default: 524288 (512k)
#[serde(default, deserialize_with = "convert_data_size_with_shellexpand")]
pub max_size: u32,
/// Due to implementation detail, we want to prefer to download
/// the first chunks of the file so we can stream the content
/// out and free up some of our buffers. This configuration
/// will be used to to restrict the number of concurrent chunk
/// downloads at a time per `get()` request.
///
/// This setting will also affect how much memory might be used
/// per `get()` request. Estimated worst case memory per `get()`
/// request is: `max_concurrent_fetch_per_get * max_size`.
///
/// Default: 10
#[serde(default, deserialize_with = "convert_numeric_with_shellexpand")]
pub max_concurrent_fetch_per_get: u32,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(deny_unknown_fields)]
#[cfg_attr(feature = "dev-schema", derive(JsonSchema))]
pub struct ExistenceCacheSpec {
/// The underlying store wrap around. All content will first flow
/// through self before forwarding to backend. In the event there
/// is an error detected in self, the connection to the backend
/// will be terminated, and early termination should always cause
/// updates to fail on the backend.
pub backend: StoreSpec,
/// Policy used to evict items out of the store. Failure to set this
/// value will cause items to never be removed from the store causing
/// infinite memory usage.
pub eviction_policy: Option<EvictionPolicy>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(deny_unknown_fields)]
#[cfg_attr(feature = "dev-schema", derive(JsonSchema))]
pub struct VerifySpec {
/// The underlying store wrap around. All content will first flow
/// through self before forwarding to backend. In the event there
/// is an error detected in self, the connection to the backend
/// will be terminated, and early termination should always cause
/// updates to fail on the backend.
pub backend: StoreSpec,
/// If set the store will verify the size of the data before accepting
/// an upload of data.
///
/// This should be set to false for AC, but true for CAS stores.
#[serde(default, deserialize_with = "convert_boolean_with_shellexpand")]
pub verify_size: bool,
/// If the data should be hashed and verify that the key matches the
/// computed hash. The hash function is automatically determined based
/// request and if not set will use the global default.
///
/// This should be set to false for AC, but true for CAS stores.
#[serde(default, deserialize_with = "convert_boolean_with_shellexpand")]
pub verify_hash: bool,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(deny_unknown_fields)]
#[cfg_attr(feature = "dev-schema", derive(JsonSchema))]
pub struct CompletenessCheckingSpec {
/// The underlying store that will have it's results validated before sending to client.
pub backend: StoreSpec,
/// When a request is made, the results are decoded and all output digests/files are verified
/// to exist in this CAS store before returning success.
pub cas_store: StoreSpec,
}
#[derive(Serialize, Deserialize, Debug, Default, PartialEq, Eq, Clone, Copy)]
#[serde(deny_unknown_fields)]
#[cfg_attr(feature = "dev-schema", derive(JsonSchema))]
pub struct Lz4Config {
/// Size of the blocks to compress.
/// Higher values require more ram, but might yield slightly better
/// compression ratios.
///
/// Default: 65536 (64k).
#[serde(default, deserialize_with = "convert_data_size_with_shellexpand")]
pub block_size: u32,
/// Maximum size allowed to attempt to deserialize data into.
/// This is needed because the `block_size` is embedded into the data
/// so if there was a bad actor, they could upload an extremely large
/// `block_size`'ed entry and we'd allocate a large amount of memory
/// when retrieving the data. To prevent this from happening, we
/// allow you to specify the maximum that we'll attempt deserialize.
///
/// Default: value in `block_size`.
#[serde(default, deserialize_with = "convert_data_size_with_shellexpand")]
pub max_decode_block_size: u32,
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone, Copy)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "dev-schema", derive(JsonSchema))]
pub enum CompressionAlgorithm {
/// LZ4 compression algorithm is extremely fast for compression and
/// decompression, however does not perform very well in compression
/// ratio. In most cases build artifacts are highly compressible, however
/// lz4 is quite good at aborting early if the data is not deemed very
/// compressible.
///
/// see: <https://lz4.github.io/lz4/>
Lz4(Lz4Config),
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(deny_unknown_fields)]
#[cfg_attr(feature = "dev-schema", derive(JsonSchema))]
pub struct CompressionSpec {
/// The underlying store wrap around. All content will first flow
/// through self before forwarding to backend. In the event there
/// is an error detected in self, the connection to the backend
/// will be terminated, and early termination should always cause
/// updates to fail on the backend.
pub backend: StoreSpec,
/// The compression algorithm to use.
pub compression_algorithm: CompressionAlgorithm,
}
/// Eviction policy always works on LRU (Least Recently Used). Any time an entry
/// is touched it updates the timestamp. Inserts and updates will execute the
/// eviction policy removing any expired entries and/or the oldest entries
/// until the store size becomes smaller than `max_bytes`.
#[derive(Serialize, Deserialize, Debug, Default, Clone, Copy)]
#[serde(deny_unknown_fields)]
#[cfg_attr(feature = "dev-schema", derive(JsonSchema))]
pub struct EvictionPolicy {
/// Maximum number of bytes before eviction takes place.
/// Default: 0. Zero means never evict based on size.
#[serde(default, deserialize_with = "convert_data_size_with_shellexpand")]
pub max_bytes: usize,
/// When eviction starts based on hitting `max_bytes`, continue until
/// `max_bytes - evict_bytes` is met to create a low watermark. This stops
/// operations from thrashing when the store is close to the limit.
/// Default: 0
#[serde(default, deserialize_with = "convert_data_size_with_shellexpand")]
pub evict_bytes: usize,
/// Maximum number of seconds for an entry to live since it was last
/// accessed before it is evicted.
/// Default: 0. Zero means never evict based on time.
#[serde(default, deserialize_with = "convert_duration_with_shellexpand")]
pub max_seconds: u32,
/// Maximum size of the store before an eviction takes place.
/// Default: 0. Zero means never evict based on count.
#[serde(default, deserialize_with = "convert_numeric_with_shellexpand")]
pub max_count: u64,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(tag = "provider", rename_all = "snake_case")]
#[cfg_attr(feature = "dev-schema", derive(JsonSchema))]
pub enum ExperimentalCloudObjectSpec {
Aws(ExperimentalAwsSpec),
Gcs(ExperimentalGcsSpec),
Azure(ExperimentalAzureSpec),
Ontap(ExperimentalOntapS3Spec),
}
impl Default for ExperimentalCloudObjectSpec {
fn default() -> Self {
Self::Aws(ExperimentalAwsSpec::default())
}
}
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
#[serde(deny_unknown_fields)]
#[cfg_attr(feature = "dev-schema", derive(JsonSchema))]
pub struct ExperimentalAwsSpec {
/// S3 region. Usually us-east-1, us-west-2, af-south-1, exc...
#[serde(default, deserialize_with = "convert_string_with_shellexpand")]
pub region: String,
/// Bucket name to use as the backend.
#[serde(default, deserialize_with = "convert_string_with_shellexpand")]
pub bucket: String,
/// Common retry and upload configuration
#[serde(flatten)]