-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathdbinit.sql
1924 lines (1623 loc) · 52.8 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:
*
* The syntax STRING(63) means a Unicode string with at most 63 code points,
* not 63 bytes. In many cases, Nexus itself will validate a string's
* byte count or code points, so it's still reasonable to limit ourselves to
* powers of two (or powers-of-two-minus-one) to improve storage utilization.
*
* 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."
*/
/*
* 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 omicron;
CREATE USER omicron;
ALTER DEFAULT PRIVILEGES GRANT INSERT, SELECT, UPDATE, DELETE ON TABLES to omicron;
/*
* Racks
*/
CREATE TABLE 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)
);
/*
* Sleds
*/
CREATE TABLE 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,
/* 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 an Oxide service on this sled. */
last_used_address INET NOT NULL
);
/* Add an index which lets us look up sleds on a rack */
CREATE INDEX ON omicron.public.sled (
rack_id
) WHERE time_deleted IS NULL;
CREATE INDEX ON omicron.public.sled (
id
) WHERE
time_deleted IS NULL;
/*
* Services
*/
CREATE TYPE omicron.public.service_kind AS ENUM (
'internal_dns',
'nexus',
'oximeter',
'dendrite',
'tfport',
'crucible_pantry'
);
CREATE TABLE omicron.public.service (
/* Identity metadata (asset) */
id UUID PRIMARY KEY,
time_created TIMESTAMPTZ NOT NULL,
time_modified TIMESTAMPTZ NOT NULL,
/* FK into the Sled table */
sled_id UUID NOT NULL,
/* The IP address of the service. */
ip INET NOT NULL,
/* Indicates the type of service. */
kind omicron.public.service_kind NOT NULL
);
/* Add an index which lets us look up the services on a sled */
CREATE INDEX ON omicron.public.service (
sled_id
);
CREATE TYPE omicron.public.physical_disk_kind AS ENUM (
'm2',
'u2'
);
-- A physical disk which exists inside the rack.
CREATE TABLE 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,
-- This constraint should be upheld, even for deleted disks
-- in the fleet.
CONSTRAINT vendor_serial_model_unique UNIQUE (
vendor, serial, model
)
);
CREATE INDEX ON omicron.public.physical_disk (
variant,
id
) WHERE time_deleted IS NULL;
-- Make it efficient to look up physical disks by Sled.
CREATE INDEX ON omicron.public.physical_disk (
sled_id,
id
) WHERE time_deleted IS NULL;
-- x509 certificates which may be used by services
CREATE TABLE 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,
-- The service type which should use this certificate
service omicron.public.service_kind NOT NULL,
-- cert.pem file as a binary blob
cert BYTES NOT NULL,
-- key.pem file as a binary blob
key BYTES NOT NULL
);
-- Add an index which lets us look up certificates for a particular service
-- class.
CREATE INDEX 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 ON omicron.public.certificate (
name
) WHERE
time_deleted IS NULL;
-- A table describing virtual resource provisioning which may be associated
-- with a collection of objects, including:
-- - Projects
-- - Organizations
-- - Silos
-- - Fleet
CREATE TABLE 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 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.
* Typically these are backed by a single physical disk.
*/
CREATE TABLE 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,
/* TODO: Could also store physical disk FK here */
total_size INT NOT NULL
);
CREATE TYPE omicron.public.dataset_kind AS ENUM (
'crucible',
'cockroach',
'clickhouse'
);
/*
* A dataset of allocated space within a zpool.
*/
CREATE TABLE omicron.public.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 */
ip INET NOT NULL,
port INT4 CHECK (port BETWEEN 0 AND 65535) NOT NULL,
kind omicron.public.dataset_kind NOT NULL,
/* An upper bound on the amount of space that might be in-use */
size_used INT,
/* Crucible must make use of 'size_used'; other datasets manage their own storage */
CONSTRAINT size_used_column_set_for_crucible CHECK (
(kind != 'crucible') OR
(kind = 'crucible' AND size_used IS NOT NULL)
)
);
/* Create an index on the size usage for Crucible's allocation */
CREATE INDEX on omicron.public.Dataset (
size_used
) WHERE size_used IS NOT NULL AND time_deleted IS NULL AND kind = 'crucible';
/* Create an index on the size usage for any dataset */
CREATE INDEX on omicron.public.Dataset (
size_used
) WHERE size_used IS NOT NULL AND time_deleted IS NULL;
/*
* A region of space allocated to Crucible Downstairs, within a dataset.
*/
CREATE TABLE 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
);
/*
* Allow all regions belonging to a disk to be accessed quickly.
*/
CREATE INDEX on omicron.public.Region (
volume_id
);
/*
* Allow all regions belonging to a dataset to be accessed quickly.
*/
CREATE INDEX on omicron.public.Region (
dataset_id
);
/*
* A snapshot of a region, within a dataset.
*/
CREATE TABLE 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,
PRIMARY KEY (dataset_id, region_id, snapshot_id)
);
/* Index for use during join with region table */
CREATE INDEX on omicron.public.region_snapshot (
dataset_id, region_id
);
/*
* Index on volume_references and snapshot_addr for crucible
* resource accounting lookup
*/
CREATE INDEX on omicron.public.region_snapshot (
volume_references
);
CREATE INDEX on omicron.public.region_snapshot (
snapshot_addr
);
/*
* A volume within Crucible
*/
CREATE TABLE 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 on omicron.public.volume (
time_deleted
);
/*
* Silos
*/
CREATE TYPE omicron.public.authentication_mode AS ENUM (
'local',
'saml'
);
CREATE TYPE omicron.public.user_provision_type AS ENUM (
'api_only',
'jit'
);
CREATE TABLE 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,
/* child resource generation number, per RFD 192 */
rcgen INT NOT NULL
);
CREATE UNIQUE INDEX ON omicron.public.silo (
name
) WHERE
time_deleted IS NULL;
/*
* Silo users
*/
CREATE TABLE 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 ON omicron.public.silo_user (
silo_id,
external_id
) WHERE
time_deleted IS NULL;
CREATE TABLE 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 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 ON omicron.public.silo_group (
silo_id,
external_id
) WHERE
time_deleted IS NULL;
/*
* Silo group membership
*/
CREATE TABLE 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)
);
CREATE INDEX ON omicron.public.silo_group_membership (
silo_user_id,
silo_group_id
);
/*
* Silo identity provider list
*/
CREATE TYPE omicron.public.provider_type AS ENUM (
'saml'
);
CREATE TABLE 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 INDEX ON omicron.public.identity_provider (
id,
silo_id
) WHERE
time_deleted IS NULL;
CREATE INDEX ON omicron.public.identity_provider (
name,
silo_id
) WHERE
time_deleted IS NULL;
/*
* Silo SAML identity provider
*/
CREATE TABLE 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 INDEX ON omicron.public.saml_identity_provider (
id,
silo_id
) WHERE
time_deleted IS NULL;
/*
* Users' public SSH keys, per RFD 44
*/
CREATE TABLE omicron.public.ssh_key (
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,
/* FK into silo_user table */
silo_user_id UUID NOT NULL,
/*
* A 4096 bit RSA key without comment encodes to 726 ASCII characters.
* A (256 bit) Ed25519 key w/o comment encodes to 82 ASCII characters.
*/
public_key STRING(1023) NOT NULL
);
CREATE UNIQUE INDEX ON omicron.public.ssh_key (
silo_user_id,
name
) WHERE
time_deleted IS NULL;
/*
* Organizations
*/
CREATE TABLE omicron.public.organization (
/* Identity metadata */
id UUID PRIMARY KEY,
/* FK into Silo table */
silo_id UUID NOT NULL,
name STRING(63) NOT NULL,
description STRING(512) NOT NULL,
time_created TIMESTAMPTZ NOT NULL,
time_modified TIMESTAMPTZ NOT NULL,
/* Indicates that the object has been deleted */
time_deleted TIMESTAMPTZ,
/* child resource generation number, per RFD 192 */
rcgen INT NOT NULL
);
CREATE UNIQUE INDEX ON omicron.public.organization (
silo_id,
name
) WHERE
time_deleted IS NULL;
/*
* Projects
*/
CREATE TABLE omicron.public.project (
/* 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,
/* Indicates that the object has been deleted */
time_deleted TIMESTAMPTZ,
/* child resource generation number, per RFD 192 */
rcgen INT NOT NULL,
/* Which organization this project belongs to */
organization_id UUID NOT NULL /* foreign key into "Organization" table */
);
CREATE UNIQUE INDEX ON omicron.public.project (
organization_id,
name
) WHERE
time_deleted IS NULL;
/*
* Instances
*/
CREATE TYPE omicron.public.instance_state AS ENUM (
'creating',
'starting',
'running',
'stopping',
'stopped',
'rebooting',
'migrating',
'repairing',
'failed',
'destroyed'
);
/*
* TODO consider how we want to manage multiple sagas operating on the same
* Instance -- e.g., reboot concurrent with destroy or concurrent reboots or the
* like. Or changing # of CPUs or memory size.
*/
CREATE TABLE omicron.public.instance (
/* 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,
/* Indicates that the object has been deleted */
/* This is redundant for Instances, but we keep it here for consistency. */
time_deleted TIMESTAMPTZ,
/* Every Instance is in exactly one Project at a time. */
project_id UUID NOT NULL,
/* user data for instance initialization systems (e.g. cloud-init) */
user_data BYTES NOT NULL,
/*
* TODO Would it make sense for the runtime state to live in a separate
* table?
*/
/* Runtime state */
state omicron.public.instance_state NOT NULL,
time_state_updated TIMESTAMPTZ NOT NULL,
state_generation INT NOT NULL,
/*
* Server where the VM is currently running, if any. Note that when we
* support live migration, there may be multiple servers associated with
* this Instance, but only one will be truly active. Still, consumers of
* this information should consider whether they also want to know the other
* servers involved in the migration.
*/
active_server_id UUID,
/* Identifies the underlying propolis-server backing the instance. */
active_propolis_id UUID NOT NULL,
active_propolis_ip INET,
/* Identifies the target propolis-server during a migration of the instance. */
target_propolis_id UUID,
/*
* Identifies an ongoing migration for this instance.
*/
migration_id UUID,
/* Instance configuration */
ncpus INT NOT NULL,
memory INT NOT NULL,
hostname STRING(63) NOT NULL
);
CREATE UNIQUE INDEX ON omicron.public.instance (
project_id,
name
) WHERE
time_deleted IS NULL;
/*
* Guest-Visible, Virtual Disks
*/
/*
* TODO The Rust enum to which this type is converted
* carries data in some of its variants, such as the UUID
* of the instance to which a disk is attached.
*
* This makes the conversion to/from this enum type here much
* more difficult, since we need a way to manage that data
* coherently.
*
* See <https://github.com/oxidecomputer/omicron/issues/312>.
*/
-- CREATE TYPE omicron.public.DiskState AS ENUM (
-- 'creating',
-- 'detached',
-- 'attaching',
-- 'attached',
-- 'detaching',
-- 'destroyed',
-- 'faulted'
-- );
CREATE TYPE omicron.public.block_size AS ENUM (
'512',
'2048',
'4096'
);
CREATE TABLE omicron.public.disk (
/* 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,
/* Indicates that the object has been deleted */
/* This is redundant for Disks, but we keep it here for consistency. */
time_deleted TIMESTAMPTZ,
/* child resource generation number, per RFD 192 */
rcgen INT NOT NULL,
/* Every Disk is in exactly one Project at a time. */
project_id UUID NOT NULL,
/* Every disk consists of a root volume */
volume_id UUID NOT NULL,
/*
* TODO Would it make sense for the runtime state to live in a separate
* table?
*/
/* Runtime state */
-- disk_state omicron.public.DiskState NOT NULL, /* TODO see above */
disk_state STRING(15) NOT NULL,
/*
* Every Disk may be attaching to, attached to, or detaching from at most
* one Instance at a time.
*/
attach_instance_id UUID,
state_generation INT NOT NULL,
time_state_updated TIMESTAMPTZ NOT NULL,
/* Disk configuration */
size_bytes INT NOT NULL,
block_size omicron.public.block_size NOT NULL,
origin_snapshot UUID,
origin_image UUID
);
CREATE UNIQUE INDEX ON omicron.public.disk (
project_id,
name
) WHERE
time_deleted IS NULL;
CREATE INDEX ON omicron.public.disk (
attach_instance_id
) WHERE
time_deleted IS NULL AND attach_instance_id IS NOT NULL;
CREATE TABLE omicron.public.image (
/* 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,
/* Indicates that the object has been deleted */
time_deleted TIMESTAMPTZ,
project_id UUID NOT NULL,
volume_id UUID NOT NULL,
url STRING(8192),
version STRING(64),
digest TEXT,
block_size omicron.public.block_size NOT NULL,
size_bytes INT NOT NULL
);
CREATE UNIQUE INDEX on omicron.public.image (
project_id,
name
) WHERE
time_deleted is NULL;
CREATE TABLE omicron.public.global_image (
/* 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,
/* Indicates that the object has been deleted */
time_deleted TIMESTAMPTZ,
volume_id UUID NOT NULL,
url STRING(8192),
distribution STRING(64) NOT NULL,
version STRING(64) NOT NULL,
digest TEXT,
block_size omicron.public.block_size NOT NULL,
size_bytes INT NOT NULL
);
CREATE UNIQUE INDEX on omicron.public.global_image (
name
) WHERE
time_deleted is NULL;
CREATE TYPE omicron.public.snapshot_state AS ENUM (
'creating',
'ready',
'faulted',
'destroyed'
);
CREATE TABLE omicron.public.snapshot (
/* 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,
/* Indicates that the object has been deleted */
time_deleted TIMESTAMPTZ,
/* Every Snapshot is in exactly one Project at a time. */
project_id UUID NOT NULL,
/* Every Snapshot originated from a single disk */
disk_id UUID NOT NULL,
/* Every Snapshot consists of a root volume */
volume_id UUID NOT NULL,
/* Where will the scrubbed blocks eventually land? */
destination_volume_id UUID NOT NULL,
gen INT NOT NULL,
state omicron.public.snapshot_state NOT NULL,
block_size omicron.public.block_size NOT NULL,
/* Disk configuration (from the time the snapshot was taken) */
size_bytes INT NOT NULL
);
CREATE UNIQUE INDEX ON omicron.public.snapshot (
project_id,
name
) WHERE
time_deleted IS NULL;
/*
* Oximeter collector servers.
*/
CREATE TABLE omicron.public.oximeter (
id UUID PRIMARY KEY,
time_created TIMESTAMPTZ NOT NULL,
time_modified TIMESTAMPTZ NOT NULL,
ip INET NOT NULL,
port INT4 CHECK (port BETWEEN 0 AND 65535) NOT NULL
);
/*
* Information about registered metric producers.
*/
CREATE TABLE omicron.public.metric_producer (
id UUID PRIMARY KEY,
time_created TIMESTAMPTZ NOT NULL,
time_modified TIMESTAMPTZ NOT NULL,
ip INET NOT NULL,
port INT4 CHECK (port BETWEEN 0 AND 65535) NOT NULL,
interval FLOAT NOT NULL,
/* TODO: Is this length appropriate? */
base_route STRING(512) NOT NULL,
/* Oximeter collector instance to which this metric producer is assigned. */
oximeter_id UUID NOT NULL
);
CREATE UNIQUE INDEX ON omicron.public.metric_producer (
oximeter_id,
id
);
/*
* VPCs and networking primitives
*/
CREATE TABLE omicron.public.vpc (
/* 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,
/* Indicates that the object has been deleted */
time_deleted TIMESTAMPTZ,
project_id UUID NOT NULL,
system_router_id UUID NOT NULL,
dns_name STRING(63) NOT NULL,