-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathdbinit.sql
5104 lines (4324 loc) · 160 KB
/
dbinit.sql
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
/*
* dbinit.sql: raw SQL to initialize a database for use by Omicron
*
* It's not clear what the long-term story for managing the database schema will
* be. For now, this file can be used by the test suite and by developers (via
* the "omicron-dev" program) to set up a local database with which to run the
* system.
*/
/*
* Important CockroachDB notes:
*
* For timestamps, CockroachDB's docs recommend TIMESTAMPTZ rather than
* TIMESTAMP. This does not change what is stored with each datum, but
* rather how it's interpreted when clients use it. It should make no
* difference to us, so we stick with the recommendation.
*
* We avoid explicit foreign keys due to this warning from the docs: "Foreign
* key dependencies can significantly impact query performance, as queries
* involving tables with foreign keys, or tables referenced by foreign keys,
* require CockroachDB to check two separate tables. We recommend using them
* sparingly."
*/
BEGIN;
/*
* We assume the database and user do not already exist so that we don't
* inadvertently clobber what's there. If they might exist, the user has to
* clear this first.
*
* NOTE: the database and user names MUST be kept in sync with the
* initialization code and dbwipe.sql.
*/
CREATE DATABASE IF NOT EXISTS omicron;
CREATE USER IF NOT EXISTS omicron;
ALTER DEFAULT PRIVILEGES GRANT INSERT, SELECT, UPDATE, DELETE ON TABLES to omicron;
/*
* Configure a replication factor of 5 to ensure that the system can maintain
* availability in the face of any two node failures.
*/
ALTER RANGE default CONFIGURE ZONE USING num_replicas = 5;
/*
* The deployment strategy for clickhouse
*/
CREATE TYPE IF NOT EXISTS omicron.public.clickhouse_mode AS ENUM (
-- Only deploy a single node clickhouse
'single_node_only',
-- Only deploy a clickhouse cluster without any single node deployments
'cluster_only',
-- Deploy both a single node and cluster deployment.
-- This is the strategy for stage 1 described in RFD 468
'both'
);
/*
* A planning policy for clickhouse for a single multirack setup
*
* We currently implicitly tie this policy to a rack, as we don't yet support
* multirack. Multiple parts of this database schema are going to have to change
* to support multirack, so we add one more for now.
*/
CREATE TABLE IF NOT EXISTS omicron.public.clickhouse_policy (
-- Monotonically increasing version for all policies
--
-- This is similar to `bp_target` which will also require being changed for
-- multirack to associate with some sort of rack group ID.
version INT8 PRIMARY KEY,
clickhouse_mode omicron.public.clickhouse_mode NOT NULL,
-- Only greater than 0 when clickhouse cluster is enabled
clickhouse_cluster_target_servers INT2 NOT NULL,
-- Only greater than 0 when clickhouse cluster is enabled
clickhouse_cluster_target_keepers INT2 NOT NULL,
time_created TIMESTAMPTZ NOT NULL
);
/*
* The ClickHouse installation Oximeter should read from
*/
CREATE TYPE IF NOT EXISTS omicron.public.oximeter_read_mode AS ENUM (
-- Read from the single node ClickHouse installation
'single_node',
-- Read from the replicated ClickHouse cluster
'cluster'
);
/*
* A planning policy for oximeter_read for a single multirack setup
*/
CREATE TABLE IF NOT EXISTS omicron.public.oximeter_read_policy (
-- Monotonically increasing version for all policies
version INT8 PRIMARY KEY,
oximeter_read_mode omicron.public.oximeter_read_mode NOT NULL,
time_created TIMESTAMPTZ NOT NULL
);
/*
* Oximeter read policy defaults to reading from a single node ClickHouse server.
*/
INSERT INTO omicron.public.oximeter_read_policy (
version,
oximeter_read_mode,
time_created
) VALUES (
1,
'single_node',
NOW()
) ON CONFLICT DO NOTHING;
/*
* Racks
*/
CREATE TABLE IF NOT EXISTS omicron.public.rack (
/* Identity metadata (asset) */
id UUID PRIMARY KEY,
time_created TIMESTAMPTZ NOT NULL,
time_modified TIMESTAMPTZ NOT NULL,
/*
* Identifies if rack management has been transferred from RSS -> Nexus.
* If "false", RSS is still managing sleds, services, and DNS records.
*
* This value is set to "true" when RSS calls the
* "rack_initialization_complete" endpoint on Nexus' internal interface.
*
* See RFD 278 for more detail.
*/
initialized BOOL NOT NULL,
/* Used to configure the updates service URL */
tuf_base_url STRING(512),
/* The IPv6 underlay /56 prefix for the rack */
rack_subnet INET
);
/*
* Sleds
*/
-- The disposition for a particular sled. This is updated solely by the
-- operator, and not by Nexus.
CREATE TYPE IF NOT EXISTS omicron.public.sled_policy AS ENUM (
-- The sled is in service, and new resources can be provisioned onto it.
'in_service',
-- The sled is in service, but the operator has indicated that new
-- resources should not be provisioned onto it.
'no_provision',
-- The operator has marked that the sled has, or will be, removed from the
-- rack, and it should be assumed that any resources currently on it are
-- now permanently missing.
'expunged'
);
-- The actual state of the sled. This is updated exclusively by Nexus.
--
-- Nexus's goal is to match the sled's state with the operator-indicated
-- policy. For example, if the sled_policy is "expunged" and the sled_state is
-- "active", Nexus will assume that the sled is gone. Based on that, Nexus will
-- reallocate resources currently on the expunged sled to other sleds, etc.
-- Once the expunged sled no longer has any resources attached to it, Nexus
-- will mark it as decommissioned.
CREATE TYPE IF NOT EXISTS omicron.public.sled_state AS ENUM (
-- The sled has resources of any kind allocated on it, or, is available for
-- new resources.
--
-- The sled can be in this state and have a different sled policy, e.g.
-- "expunged".
'active',
-- The sled no longer has resources allocated on it, now or in the future.
--
-- This is a terminal state. This state is only valid if the sled policy is
-- 'expunged'.
'decommissioned'
);
CREATE TABLE IF NOT EXISTS omicron.public.sled (
/* Identity metadata (asset) */
id UUID PRIMARY KEY,
time_created TIMESTAMPTZ NOT NULL,
time_modified TIMESTAMPTZ NOT NULL,
time_deleted TIMESTAMPTZ,
rcgen INT NOT NULL,
/* FK into the Rack table */
rack_id UUID NOT NULL,
/* Idenfities if this Sled is a Scrimlet */
is_scrimlet BOOL NOT NULL,
/* Baseboard information about the sled */
serial_number STRING(63) NOT NULL,
part_number STRING(63) NOT NULL,
revision INT8 NOT NULL,
/* CPU & RAM summary for the sled */
usable_hardware_threads INT8 CHECK (usable_hardware_threads BETWEEN 0 AND 4294967295) NOT NULL,
usable_physical_ram INT8 NOT NULL,
reservoir_size INT8 CHECK (reservoir_size < usable_physical_ram) NOT NULL,
/* The IP address and bound port of the sled agent server. */
ip INET NOT NULL,
port INT4 CHECK (port BETWEEN 0 AND 65535) NOT NULL,
/* The last address allocated to a propolis instance on this sled. */
last_used_address INET NOT NULL,
/* The policy for the sled, updated exclusively by the operator */
sled_policy omicron.public.sled_policy NOT NULL,
/* The actual state of the sled, updated exclusively by Nexus */
sled_state omicron.public.sled_state NOT NULL,
/* Generation number owned and incremented by the sled-agent */
sled_agent_gen INT8 NOT NULL DEFAULT 1,
/* The bound port of the Repo Depot API server, running on the same IP as
the sled agent server. */
repo_depot_port INT4 CHECK (port BETWEEN 0 AND 65535) NOT NULL
);
-- Add an index that ensures a given physical sled (identified by serial and
-- part number) can only be a commissioned member of the control plane once.
--
-- TODO Should `sled` reference `hw_baseboard_id` instead of having its own
-- serial/part columns?
CREATE UNIQUE INDEX IF NOT EXISTS commissioned_sled_uniqueness
ON omicron.public.sled (serial_number, part_number)
WHERE sled_state != 'decommissioned';
/* Add an index which lets us look up sleds on a rack */
CREATE UNIQUE INDEX IF NOT EXISTS lookup_sled_by_rack ON omicron.public.sled (
rack_id,
id
) WHERE time_deleted IS NULL;
/* Add an index which lets us look up sleds based on policy and state */
CREATE INDEX IF NOT EXISTS lookup_sled_by_policy_and_state ON omicron.public.sled (
sled_policy,
sled_state
);
-- Accounting for VMMs using resources on a sled
CREATE TABLE IF NOT EXISTS omicron.public.sled_resource_vmm (
-- Should match the UUID of the corresponding VMM
id UUID PRIMARY KEY,
-- The sled where resources are being consumed
sled_id UUID NOT NULL,
-- The maximum number of hardware threads usable by this VMM
hardware_threads INT8 NOT NULL,
-- The maximum amount of RSS RAM provisioned to this VMM
rss_ram INT8 NOT NULL,
-- The maximum amount of Reservoir RAM provisioned to this VMM
reservoir_ram INT8 NOT NULL,
-- The UUID of the instance to which this VMM belongs.
--
-- This should eventually become NOT NULL for all VMMs, but is
-- still nullable for backwards compatibility purposes. Specifically,
-- the "instance start" saga can create rows in this table before creating
-- rows for "omicron.public.vmm", which we would use for back-filling.
-- If we tried to backfill + make this column non-nullable while that saga
-- was mid-execution, we would still have some rows in this table with nullable
-- values that would be more complex to fix.
instance_id UUID
);
-- Allow looking up all VMM resources which reside on a sled
CREATE UNIQUE INDEX IF NOT EXISTS lookup_vmm_resource_by_sled ON omicron.public.sled_resource_vmm (
sled_id,
id
);
-- Allow looking up all resources by instance
CREATE INDEX IF NOT EXISTS lookup_vmm_resource_by_instance ON omicron.public.sled_resource_vmm (
instance_id
);
-- Table of all sled subnets allocated for sleds added to an already initialized
-- rack. The sleds in this table and their allocated subnets are created before
-- a sled is added to the `sled` table. Addition to the `sled` table occurs
-- after the sled is initialized and notifies Nexus about itself.
--
-- For simplicity and space savings, this table doesn't actually contain the
-- full subnets for a given sled, but only the octet that extends a /56 rack
-- subnet to a /64 sled subnet. The rack subnet is maintained in the `rack`
-- table.
--
-- This table does not include subnet octets allocated during RSS and therefore
-- all of the octets start at 33. This makes the data in this table purely additive
-- post-RSS, which also implies that we cannot re-use subnet octets if an original
-- sled that was part of RSS was removed from the cluster.
CREATE TABLE IF NOT EXISTS omicron.public.sled_underlay_subnet_allocation (
-- The physical identity of the sled
-- (foreign key into `hw_baseboard_id` table)
hw_baseboard_id UUID,
-- The rack to which a sled is being added
-- (foreign key into `rack` table)
--
-- We require this because the sled is not yet part of the sled table when
-- we first allocate a subnet for it.
rack_id UUID NOT NULL,
-- The sled to which a subnet is being allocated
--
-- Eventually will be a foreign key into the `sled` table when the sled notifies nexus
-- about itself after initialization.
sled_id UUID NOT NULL,
-- The octet that extends a /56 rack subnet to a /64 sled subnet
--
-- Always between 33 and 255 inclusive
subnet_octet INT2 NOT NULL UNIQUE CHECK (subnet_octet BETWEEN 33 AND 255),
PRIMARY KEY (hw_baseboard_id, sled_id)
);
-- Add an index which allows pagination by {rack_id, sled_id} pairs.
CREATE UNIQUE INDEX IF NOT EXISTS lookup_subnet_allocation_by_rack_and_sled ON omicron.public.sled_underlay_subnet_allocation (
rack_id,
sled_id
);
/*
* Switches
*/
CREATE TABLE IF NOT EXISTS omicron.public.switch (
/* Identity metadata (asset) */
id UUID PRIMARY KEY,
time_created TIMESTAMPTZ NOT NULL,
time_modified TIMESTAMPTZ NOT NULL,
time_deleted TIMESTAMPTZ,
rcgen INT NOT NULL,
/* FK into the Rack table */
rack_id UUID NOT NULL,
/* Baseboard information about the switch */
serial_number STRING(63) NOT NULL,
part_number STRING(63) NOT NULL,
revision INT8 NOT NULL
);
/* Add an index which lets us look up switches on a rack */
CREATE UNIQUE INDEX IF NOT EXISTS lookup_switch_by_rack ON omicron.public.switch (
rack_id,
id
) WHERE time_deleted IS NULL;
/*
* Services
*/
CREATE TYPE IF NOT EXISTS omicron.public.service_kind AS ENUM (
'clickhouse',
'clickhouse_keeper',
'clickhouse_server',
'cockroach',
'crucible',
'crucible_pantry',
'dendrite',
'external_dns',
'internal_dns',
'nexus',
'ntp',
'oximeter',
'tfport',
'mgd'
);
CREATE TYPE IF NOT EXISTS omicron.public.physical_disk_kind AS ENUM (
'm2',
'u2'
);
-- The disposition for a particular physical disk.
-- This is updated by the operator, either explicitly through an operator API,
-- or implicitly when altering sled policy.
CREATE TYPE IF NOT EXISTS omicron.public.physical_disk_policy AS ENUM (
-- The disk is in service, and new resources can be provisioned onto it.
'in_service',
-- The disk has been, or will be, removed from the rack, and it should be
-- assumed that any resources currently on it are now permanently missing.
'expunged'
);
-- The actual state of a physical disk. This is updated exclusively by Nexus.
--
-- Nexus's goal is to match the physical disk's state with the
-- operator-indicated policy. For example, if the policy is "expunged" and the
-- state is "active", Nexus will assume that the physical disk is gone. Based
-- on that, Nexus will reallocate resources currently on the expunged disk
-- elsewhere, etc. Once the expunged disk no longer has any resources attached
-- to it, Nexus will mark it as decommissioned.
CREATE TYPE IF NOT EXISTS omicron.public.physical_disk_state AS ENUM (
-- The disk has resources of any kind allocated on it, or, is available for
-- new resources.
--
-- The disk can be in this state and have a different policy, e.g.
-- "expunged".
'active',
-- The disk no longer has resources allocated on it, now or in the future.
--
-- This is a terminal state. This state is only valid if the policy is
-- 'expunged'.
'decommissioned'
);
-- A physical disk which exists inside the rack.
CREATE TABLE IF NOT EXISTS omicron.public.physical_disk (
id UUID PRIMARY KEY,
time_created TIMESTAMPTZ NOT NULL,
time_modified TIMESTAMPTZ NOT NULL,
time_deleted TIMESTAMPTZ,
rcgen INT NOT NULL,
vendor STRING(63) NOT NULL,
serial STRING(63) NOT NULL,
model STRING(63) NOT NULL,
variant omicron.public.physical_disk_kind NOT NULL,
-- FK into the Sled table
sled_id UUID NOT NULL,
disk_policy omicron.public.physical_disk_policy NOT NULL,
disk_state omicron.public.physical_disk_state NOT NULL
);
-- This constraint only needs to be upheld for disks that are not deleted
-- nor decommissioned.
CREATE UNIQUE INDEX IF NOT EXISTS vendor_serial_model_unique on omicron.public.physical_disk (
vendor, serial, model
) WHERE time_deleted IS NULL AND disk_state != 'decommissioned';
CREATE UNIQUE INDEX IF NOT EXISTS lookup_physical_disk_by_variant ON omicron.public.physical_disk (
variant,
id
) WHERE time_deleted IS NULL;
-- Make it efficient to look up physical disks by Sled.
CREATE UNIQUE INDEX IF NOT EXISTS lookup_physical_disk_by_sled ON omicron.public.physical_disk (
sled_id,
id
);
-- x509 certificates which may be used by services
CREATE TABLE IF NOT EXISTS omicron.public.certificate (
-- Identity metadata (resource)
id UUID PRIMARY KEY,
name STRING(63) NOT NULL,
description STRING(512) NOT NULL,
time_created TIMESTAMPTZ NOT NULL,
time_modified TIMESTAMPTZ NOT NULL,
time_deleted TIMESTAMPTZ,
-- which Silo this certificate is used for
silo_id UUID NOT NULL,
-- The service type which should use this certificate
service omicron.public.service_kind NOT NULL,
-- cert.pem file (certificate chain in PEM format) as a binary blob
cert BYTES NOT NULL,
-- key.pem file (private key in PEM format) as a binary blob
key BYTES NOT NULL
);
-- Add an index which lets us look up certificates for a particular service
-- class.
CREATE UNIQUE INDEX IF NOT EXISTS lookup_certificate_by_service ON omicron.public.certificate (
service,
id
) WHERE
time_deleted IS NULL;
-- Add an index which enforces that certificates have unique names, and which
-- allows pagination-by-name.
CREATE UNIQUE INDEX IF NOT EXISTS lookup_certificate_by_silo ON omicron.public.certificate (
silo_id,
name
) WHERE
time_deleted IS NULL;
-- A table describing virtual resource provisioning which may be associated
-- with a collection of objects, including:
-- - Projects
-- - Silos
-- - Fleet
CREATE TABLE IF NOT EXISTS omicron.public.virtual_provisioning_collection (
-- Should match the UUID of the corresponding collection.
id UUID PRIMARY KEY,
time_modified TIMESTAMPTZ NOT NULL DEFAULT NOW(),
-- Identifies the type of the collection.
collection_type STRING(63) NOT NULL,
-- The amount of physical disk space which has been provisioned
-- on behalf of the collection.
virtual_disk_bytes_provisioned INT8 NOT NULL,
-- The number of CPUs provisioned by VMs.
cpus_provisioned INT8 NOT NULL,
-- The amount of RAM provisioned by VMs.
ram_provisioned INT8 NOT NULL
);
-- A table describing a single virtual resource which has been provisioned.
-- This may include:
-- - Disks
-- - Instances
-- - Snapshots
--
-- NOTE: You might think to yourself: "This table looks an awful lot like
-- the 'virtual_provisioning_collection' table, could they be condensed into
-- a single table?"
-- The answer to this question is unfortunately: "No". We use CTEs to both
-- UPDATE the collection table while INSERTing rows in the resource table, and
-- this would not be allowed if they came from the same table due to:
-- https://www.cockroachlabs.com/docs/v22.2/known-limitations#statements-containing-multiple-modification-subqueries-of-the-same-table-are-disallowed
-- However, by using separate tables, the CTE is able to function correctly.
CREATE TABLE IF NOT EXISTS omicron.public.virtual_provisioning_resource (
-- Should match the UUID of the corresponding collection.
id UUID PRIMARY KEY,
time_modified TIMESTAMPTZ NOT NULL DEFAULT NOW(),
-- Identifies the type of the resource.
resource_type STRING(63) NOT NULL,
-- The amount of physical disk space which has been provisioned
-- on behalf of the resource.
virtual_disk_bytes_provisioned INT8 NOT NULL,
-- The number of CPUs provisioned.
cpus_provisioned INT8 NOT NULL,
-- The amount of RAM provisioned.
ram_provisioned INT8 NOT NULL
);
-- ZPools of Storage, attached to Sleds.
-- These are backed by a single physical disk.
--
-- For information about the provisioned zpool, reference the
-- "omicron.public.inv_zpool" table, which returns information
-- that has actually been returned from the underlying sled.
CREATE TABLE IF NOT EXISTS omicron.public.zpool (
/* Identity metadata (asset) */
id UUID PRIMARY KEY,
time_created TIMESTAMPTZ NOT NULL,
time_modified TIMESTAMPTZ NOT NULL,
time_deleted TIMESTAMPTZ,
rcgen INT NOT NULL,
/* FK into the Sled table */
sled_id UUID NOT NULL,
/* FK into the Physical Disk table */
physical_disk_id UUID NOT NULL,
/*
* How many bytes to reserve for non-Crucible control plane storage
*/
control_plane_storage_buffer INT NOT NULL
);
/* Create an index on the physical disk id */
CREATE INDEX IF NOT EXISTS lookup_zpool_by_disk on omicron.public.zpool (
physical_disk_id,
id
) WHERE physical_disk_id IS NOT NULL AND time_deleted IS NULL;
CREATE TYPE IF NOT EXISTS omicron.public.dataset_kind AS ENUM (
'crucible',
'cockroach',
'clickhouse',
'clickhouse_keeper',
'clickhouse_server',
'external_dns',
'internal_dns',
'zone_root',
'zone',
'debug',
'update'
);
/*
* Table tracking the contact information and size used by datasets associated
* with Crucible zones.
*
* This is a Reconfigurator rendezvous table: it reflects resources that
* Reconfigurator has ensured exist. It is always possible that a resource
* chosen from this table could be deleted after it's selected, but any
* non-deleted row in this table is guaranteed to have been created.
*/
CREATE TABLE IF NOT EXISTS omicron.public.crucible_dataset (
/* Identity metadata (asset) */
id UUID PRIMARY KEY,
time_created TIMESTAMPTZ NOT NULL,
time_modified TIMESTAMPTZ NOT NULL,
time_deleted TIMESTAMPTZ,
rcgen INT NOT NULL,
/* FK into the Pool table */
pool_id UUID NOT NULL,
/*
* Contact information for the dataset: socket address of the Crucible
* agent service that owns this dataset
*/
ip INET NOT NULL,
port INT4 CHECK (port BETWEEN 0 AND 65535) NOT NULL,
/*
* An upper bound on the amount of space that might be in-use
*
* This field is owned by Nexus. When a new row is inserted during the
* Reconfigurator rendezvous process, this field is set to 0. Reconfigurator
* otherwise ignores this field. It's updated by Nexus as region allocations
* and deletions are performed using this dataset.
*
* Note that the value in this column is _not_ the sum of requested region
* sizes, but sum of the size *reserved* by the Crucible agent for the
* dataset that contains the regions (which is larger than the the actual
* region size).
*/
size_used INT NOT NULL,
/* Do not consider this dataset during region allocation */
no_provision BOOL NOT NULL
);
/* Create an index on the size usage for any Crucible dataset */
CREATE INDEX IF NOT EXISTS lookup_crucible_dataset_by_size_used ON
omicron.public.crucible_dataset (size_used)
WHERE time_deleted IS NULL;
/* Create an index on the zpool id */
CREATE INDEX IF NOT EXISTS lookup_crucible_dataset_by_zpool ON
omicron.public.crucible_dataset (pool_id, id)
WHERE time_deleted IS NULL;
CREATE INDEX IF NOT EXISTS lookup_crucible_dataset_by_ip ON
omicron.public.crucible_dataset (ip);
CREATE TYPE IF NOT EXISTS omicron.public.region_reservation_percent AS ENUM (
'25'
);
/*
* A region of space allocated to Crucible Downstairs, within a dataset.
*/
CREATE TABLE IF NOT EXISTS omicron.public.region (
/* Identity metadata (asset) */
id UUID PRIMARY KEY,
time_created TIMESTAMPTZ NOT NULL,
time_modified TIMESTAMPTZ NOT NULL,
/* FK into the dataset table */
dataset_id UUID NOT NULL,
/* FK into the volume table */
volume_id UUID NOT NULL,
/* Metadata describing the region */
block_size INT NOT NULL,
blocks_per_extent INT NOT NULL,
extent_count INT NOT NULL,
port INT4,
read_only BOOL NOT NULL,
deleting BOOL NOT NULL,
/*
* The Crucible Agent will reserve space for a region with overhead for
* on-disk metadata that the downstairs needs to store. Record here the
* overhead associated with a specific region as this may change or be
* configurable in the future.
*/
reservation_percent omicron.public.region_reservation_percent NOT NULL
);
/*
* Allow all regions belonging to a disk to be accessed quickly.
*/
CREATE UNIQUE INDEX IF NOT EXISTS lookup_region_by_volume on omicron.public.region (
volume_id,
id
);
/*
* Allow all regions belonging to a dataset to be accessed quickly.
*/
CREATE UNIQUE INDEX IF NOT EXISTS lookup_region_by_dataset on omicron.public.region (
dataset_id,
id
);
CREATE INDEX IF NOT EXISTS lookup_regions_missing_ports
on omicron.public.region (id)
WHERE port IS NULL;
CREATE INDEX IF NOT EXISTS lookup_regions_by_read_only
on omicron.public.region (read_only);
/*
* A snapshot of a region, within a dataset.
*/
CREATE TABLE IF NOT EXISTS omicron.public.region_snapshot (
dataset_id UUID NOT NULL,
region_id UUID NOT NULL,
/* Associated higher level virtual snapshot */
snapshot_id UUID NOT NULL,
/*
* Target string, for identification as part of
* volume construction request(s)
*/
snapshot_addr TEXT NOT NULL,
/* How many volumes reference this? */
volume_references INT8 NOT NULL,
/* Is this currently part of some resources_to_delete? */
deleting BOOL NOT NULL,
PRIMARY KEY (dataset_id, region_id, snapshot_id)
);
/* Indexes for use during join with region table */
CREATE INDEX IF NOT EXISTS lookup_region_by_dataset on omicron.public.region_snapshot (
dataset_id, region_id
);
CREATE INDEX IF NOT EXISTS lookup_region_snapshot_by_region_id on omicron.public.region_snapshot (
region_id
);
CREATE INDEX IF NOT EXISTS lookup_region_snapshot_by_deleting on omicron.public.region_snapshot (
deleting
);
/*
* Index on volume_references and snapshot_addr for crucible
* resource accounting lookup
*/
CREATE INDEX IF NOT EXISTS lookup_region_snapshot_by_volume_reference on omicron.public.region_snapshot (
volume_references
);
CREATE INDEX IF NOT EXISTS lookup_region_snapshot_by_snapshot_addr on omicron.public.region_snapshot (
snapshot_addr
);
/*
* A volume within Crucible
*/
CREATE TABLE IF NOT EXISTS omicron.public.volume (
id UUID PRIMARY KEY,
time_created TIMESTAMPTZ NOT NULL,
time_modified TIMESTAMPTZ NOT NULL,
time_deleted TIMESTAMPTZ,
/* child resource generation number, per RFD 192 */
rcgen INT NOT NULL,
/*
* A JSON document describing the construction of the volume, including all
* sub volumes. This is what will be POSTed to propolis, and eventually
* consumed by some Upstairs code to perform the volume creation. The Rust
* type of this column should be Crucible::VolumeConstructionRequest.
*/
data TEXT NOT NULL,
/*
* A JSON document describing what resources to clean up when deleting this
* volume. The Rust type of this column should be the CrucibleResources
* enum.
*/
resources_to_clean_up TEXT
);
/* Quickly find deleted volumes */
CREATE INDEX IF NOT EXISTS lookup_volume_by_deleted on omicron.public.volume (
time_deleted
);
/*
* Silos
*/
CREATE TYPE IF NOT EXISTS omicron.public.authentication_mode AS ENUM (
'local',
'saml'
);
CREATE TYPE IF NOT EXISTS omicron.public.user_provision_type AS ENUM (
'api_only',
'jit'
);
CREATE TABLE IF NOT EXISTS omicron.public.silo (
/* Identity metadata */
id UUID PRIMARY KEY,
name STRING(63) NOT NULL,
description STRING(512) NOT NULL,
time_created TIMESTAMPTZ NOT NULL,
time_modified TIMESTAMPTZ NOT NULL,
time_deleted TIMESTAMPTZ,
discoverable BOOL NOT NULL,
authentication_mode omicron.public.authentication_mode NOT NULL,
user_provision_type omicron.public.user_provision_type NOT NULL,
mapped_fleet_roles JSONB NOT NULL,
/* child resource generation number, per RFD 192 */
rcgen INT NOT NULL
);
CREATE UNIQUE INDEX IF NOT EXISTS lookup_silo_by_name ON omicron.public.silo (
name
) WHERE
time_deleted IS NULL;
/*
* Silo users
*/
CREATE TABLE IF NOT EXISTS omicron.public.silo_user (
id UUID PRIMARY KEY,
time_created TIMESTAMPTZ NOT NULL,
time_modified TIMESTAMPTZ NOT NULL,
time_deleted TIMESTAMPTZ,
silo_id UUID NOT NULL,
external_id TEXT NOT NULL
);
/* This index lets us quickly find users for a given silo. */
CREATE UNIQUE INDEX IF NOT EXISTS lookup_silo_user_by_silo ON omicron.public.silo_user (
silo_id,
external_id
) WHERE
time_deleted IS NULL;
CREATE TABLE IF NOT EXISTS omicron.public.silo_user_password_hash (
silo_user_id UUID NOT NULL,
hash TEXT NOT NULL,
time_created TIMESTAMPTZ NOT NULL,
PRIMARY KEY(silo_user_id)
);
/*
* Silo groups
*/
CREATE TABLE IF NOT EXISTS omicron.public.silo_group (
id UUID PRIMARY KEY,
time_created TIMESTAMPTZ NOT NULL,
time_modified TIMESTAMPTZ NOT NULL,
time_deleted TIMESTAMPTZ,
silo_id UUID NOT NULL,
external_id TEXT NOT NULL
);
CREATE UNIQUE INDEX IF NOT EXISTS lookup_silo_group_by_silo ON omicron.public.silo_group (
silo_id,
external_id
) WHERE
time_deleted IS NULL;
/*
* Silo group membership
*/
CREATE TABLE IF NOT EXISTS omicron.public.silo_group_membership (
silo_group_id UUID NOT NULL,
silo_user_id UUID NOT NULL,
PRIMARY KEY (silo_group_id, silo_user_id)
);
/*
* The primary key lets us paginate through the users in a group. We need to
* index the same fields in the reverse order to be able to paginate through the
* groups that a user is in.
*/
CREATE INDEX IF NOT EXISTS lookup_silo_group_by_user ON omicron.public.silo_group_membership (
silo_user_id,
silo_group_id
);
/*
* Silo identity provider list
*/
CREATE TYPE IF NOT EXISTS omicron.public.provider_type AS ENUM (
'saml'
);
CREATE TABLE IF NOT EXISTS omicron.public.identity_provider (
/* Identity metadata */
id UUID PRIMARY KEY,
name STRING(63) NOT NULL,
description STRING(512) NOT NULL,
time_created TIMESTAMPTZ NOT NULL,
time_modified TIMESTAMPTZ NOT NULL,
time_deleted TIMESTAMPTZ,
silo_id UUID NOT NULL,
provider_type omicron.public.provider_type NOT NULL
);
CREATE UNIQUE INDEX IF NOT EXISTS lookup_idp_by_silo_id ON omicron.public.identity_provider (
silo_id,
id
) WHERE
time_deleted IS NULL;
CREATE UNIQUE INDEX IF NOT EXISTS lookup_idp_by_silo_name ON omicron.public.identity_provider (
silo_id,
name
) WHERE
time_deleted IS NULL;
/*
* Silo SAML identity provider
*/
CREATE TABLE IF NOT EXISTS omicron.public.saml_identity_provider (
/* Identity metadata */
id UUID PRIMARY KEY,
name STRING(63) NOT NULL,
description STRING(512) NOT NULL,
time_created TIMESTAMPTZ NOT NULL,
time_modified TIMESTAMPTZ NOT NULL,
time_deleted TIMESTAMPTZ,
silo_id UUID NOT NULL,
idp_metadata_document_string TEXT NOT NULL,
idp_entity_id TEXT NOT NULL,
sp_client_id TEXT NOT NULL,
acs_url TEXT NOT NULL,
slo_url TEXT NOT NULL,
technical_contact_email TEXT NOT NULL,
public_cert TEXT,
private_key TEXT,
group_attribute_name TEXT
);
CREATE UNIQUE INDEX IF NOT EXISTS lookup_saml_idp_by_silo_id ON omicron.public.saml_identity_provider (
silo_id,
id
) WHERE
time_deleted IS NULL;
CREATE UNIQUE INDEX IF NOT EXISTS lookup_saml_idp_by_silo_name ON omicron.public.saml_identity_provider (
silo_id,
name
) WHERE
time_deleted IS NULL;
/*
* Users' public SSH keys, per RFD 44
*/
CREATE TABLE IF NOT EXISTS omicron.public.ssh_key (
id UUID PRIMARY KEY,
name STRING(63) NOT NULL,
description STRING(512) NOT NULL,
time_created TIMESTAMPTZ NOT NULL,