-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
21.1 multi-region #27
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
SECRET_KEY = 'key' | ||
DEBUG = 'True' | ||
DB_URI = 'cockroachdb://root@127.0.0.1:<port>/movr' | ||
DB_URI = 'cockroachdb://root@127.0.0.1:26257/movr' | ||
API_KEY = 'API_key' |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,130 +4,97 @@ SET sql_safe_updates = false; | |
DROP DATABASE IF EXISTS movr CASCADE; | ||
|
||
|
||
CREATE DATABASE movr; | ||
CREATE DATABASE movr PRIMARY REGION "gcp-us-east1" REGIONS "gcp-europe-west1", "gcp-us-west1"; | ||
|
||
|
||
USE movr; | ||
|
||
|
||
CREATE TABLE IF NOT EXISTS users ( | ||
id UUID NOT NULL DEFAULT gen_random_uuid(), | ||
id UUID PRIMARY KEY NOT NULL DEFAULT gen_random_uuid(), | ||
city STRING NOT NULL, | ||
first_name STRING NULL, | ||
last_name STRING NULL, | ||
email STRING NULL, | ||
username STRING NULL, | ||
password_hash STRING NULL, | ||
is_owner BOOL NULL, | ||
CONSTRAINT "primary" PRIMARY KEY (city ASC, id ASC), | ||
CONSTRAINT check_city CHECK (city IN ('amsterdam','boston','los angeles','new york','paris','rome','san francisco','seattle','washington dc')), | ||
UNIQUE INDEX users_username_key (username ASC), | ||
FAMILY "primary" (id, city, first_name, last_name, email, username, password_hash, is_owner) | ||
) PARTITION BY LIST (city) ( | ||
PARTITION us_west VALUES IN (('seattle'), ('san francisco'), ('los angeles')), | ||
PARTITION us_east VALUES IN (('new york'), ('boston'), ('washington dc')), | ||
PARTITION europe_west VALUES IN (('amsterdam'), ('paris'), ('rome')) | ||
); | ||
|
||
ALTER PARTITION europe_west OF INDEX movr.public.users@primary CONFIGURE ZONE USING | ||
constraints = '[+region=gcp-europe-west1]'; | ||
ALTER PARTITION us_east OF INDEX movr.public.users@primary CONFIGURE ZONE USING | ||
constraints = '[+region=gcp-us-east1]'; | ||
ALTER PARTITION us_west OF INDEX movr.public.users@primary CONFIGURE ZONE USING | ||
constraints = '[+region=gcp-us-west1]' | ||
; | ||
UNIQUE INDEX users_username_key (username ASC) | ||
) LOCALITY REGIONAL BY ROW; | ||
|
||
|
||
ALTER TABLE users ADD COLUMN region crdb_internal_region AS ( | ||
CASE WHEN city = 'amsterdam' THEN 'gcp-europe-west1' | ||
WHEN city = 'paris' THEN 'gcp-europe-west1' | ||
WHEN city = 'rome' THEN 'gcp-europe-west1' | ||
WHEN city = 'new york' THEN 'gcp-us-east1' | ||
WHEN city = 'boston' THEN 'gcp-us-east1' | ||
WHEN city = 'washington dc' THEN 'gcp-us-east1' | ||
WHEN city = 'san francisco' THEN 'gcp-us-west1' | ||
WHEN city = 'seattle' THEN 'gcp-us-west1' | ||
WHEN city = 'los angeles' THEN 'gcp-us-west1' | ||
ELSE 'gcp-us-east1' | ||
END | ||
) STORED; | ||
|
||
|
||
CREATE TABLE IF NOT EXISTS vehicles ( | ||
id UUID NOT NULL DEFAULT gen_random_uuid(), | ||
id UUID PRIMARY KEY NOT NULL DEFAULT gen_random_uuid(), | ||
city STRING NOT NULL, | ||
type STRING NULL, | ||
owner_id UUID NULL, | ||
date_added DATE NULL, | ||
status STRING NULL, | ||
last_location STRING NULL, | ||
color STRING NULL, | ||
brand STRING NULL, | ||
CONSTRAINT "primary" PRIMARY KEY (city ASC, id ASC), | ||
CONSTRAINT check_city CHECK (city IN ('amsterdam','boston','los angeles','new york','paris','rome','san francisco','seattle','washington dc')), | ||
CONSTRAINT fk_city_ref_users FOREIGN KEY (city, owner_id) REFERENCES users(city, id), | ||
INDEX vehicles_auto_index_fk_city_ref_users (city ASC, owner_id ASC, status ASC) PARTITION BY LIST (city) ( | ||
PARTITION us_west VALUES IN (('seattle'), ('san francisco'), ('los angeles')), | ||
PARTITION us_east VALUES IN (('new york'), ('boston'), ('washington dc')), | ||
PARTITION europe_west VALUES IN (('amsterdam'), ('paris'), ('rome')) | ||
), | ||
FAMILY "primary" (id, city, type, owner_id, date_added, status, last_location, color, brand) | ||
) PARTITION BY LIST (city) ( | ||
PARTITION us_west VALUES IN (('seattle'), ('san francisco'), ('los angeles')), | ||
PARTITION us_east VALUES IN (('new york'), ('boston'), ('washington dc')), | ||
PARTITION europe_west VALUES IN (('amsterdam'), ('paris'), ('rome')) | ||
); | ||
|
||
ALTER PARTITION europe_west OF INDEX movr.public.vehicles@primary CONFIGURE ZONE USING | ||
constraints = '[+region=gcp-europe-west1]'; | ||
ALTER PARTITION us_east OF INDEX movr.public.vehicles@primary CONFIGURE ZONE USING | ||
constraints = '[+region=gcp-us-east1]'; | ||
ALTER PARTITION us_west OF INDEX movr.public.vehicles@primary CONFIGURE ZONE USING | ||
constraints = '[+region=gcp-us-west1]'; | ||
ALTER PARTITION europe_west OF INDEX movr.public.vehicles@vehicles_auto_index_fk_city_ref_users CONFIGURE ZONE USING | ||
constraints = '[+region=gcp-europe-west1]'; | ||
ALTER PARTITION us_east OF INDEX movr.public.vehicles@vehicles_auto_index_fk_city_ref_users CONFIGURE ZONE USING | ||
constraints = '[+region=gcp-us-east1]'; | ||
ALTER PARTITION us_west OF INDEX movr.public.vehicles@vehicles_auto_index_fk_city_ref_users CONFIGURE ZONE USING | ||
constraints = '[+region=gcp-us-west1]' | ||
; | ||
brand STRING NULL, | ||
CONSTRAINT fk_ref_users FOREIGN KEY (owner_id) REFERENCES users(id) | ||
) LOCALITY REGIONAL BY ROW; | ||
|
||
|
||
ALTER TABLE vehicles ADD COLUMN region crdb_internal_region AS ( | ||
CASE WHEN city = 'amsterdam' THEN 'gcp-europe-west1' | ||
WHEN city = 'paris' THEN 'gcp-europe-west1' | ||
WHEN city = 'rome' THEN 'gcp-europe-west1' | ||
WHEN city = 'new york' THEN 'gcp-us-east1' | ||
WHEN city = 'boston' THEN 'gcp-us-east1' | ||
WHEN city = 'washington dc' THEN 'gcp-us-east1' | ||
WHEN city = 'san francisco' THEN 'gcp-us-west1' | ||
WHEN city = 'seattle' THEN 'gcp-us-west1' | ||
WHEN city = 'los angeles' THEN 'gcp-us-west1' | ||
ELSE 'gcp-us-east1' | ||
END | ||
) STORED; | ||
|
||
|
||
CREATE TABLE rides ( | ||
id UUID NOT NULL DEFAULT gen_random_uuid(), | ||
id UUID PRIMARY KEY NOT NULL DEFAULT gen_random_uuid(), | ||
city STRING NOT NULL, | ||
vehicle_id UUID NULL, | ||
rider_id UUID NULL, | ||
rider_city STRING NOT NULL, | ||
start_location STRING NULL, | ||
end_location STRING NULL, | ||
start_time TIMESTAMPTZ NULL, | ||
end_time TIMESTAMPTZ NULL, | ||
length INTERVAL NULL, | ||
CONSTRAINT "primary" PRIMARY KEY (city ASC, id ASC), | ||
CONSTRAINT check_city CHECK (city IN ('amsterdam','boston','los angeles','new york','paris','rome','san francisco','seattle','washington dc')), | ||
CONSTRAINT fk_city_ref_users FOREIGN KEY (rider_city, rider_id) REFERENCES users(city, id), | ||
CONSTRAINT fk_vehicle_city_ref_vehicles FOREIGN KEY (city, vehicle_id) REFERENCES vehicles(city, id), | ||
INDEX rides_auto_index_fk_city_ref_users (rider_city ASC, rider_id ASC) PARTITION BY LIST (rider_city) ( | ||
PARTITION us_west VALUES IN (('seattle'), ('san francisco'), ('los angeles')), | ||
PARTITION us_east VALUES IN (('new york'), ('boston'), ('washington dc')), | ||
PARTITION europe_west VALUES IN (('amsterdam'), ('paris'), ('rome')) | ||
), | ||
INDEX rides_auto_index_fk_vehicle_city_ref_vehicles (city ASC, vehicle_id ASC) PARTITION BY LIST (city) ( | ||
PARTITION us_west VALUES IN (('seattle'), ('san francisco'), ('los angeles')), | ||
PARTITION us_east VALUES IN (('new york'), ('boston'), ('washington dc')), | ||
PARTITION europe_west VALUES IN (('amsterdam'), ('paris'), ('rome')) | ||
), | ||
FAMILY "primary" (id, city, rider_id, rider_city, vehicle_id, start_location, end_location, start_time, end_time, length) | ||
) PARTITION BY LIST (city) ( | ||
PARTITION us_west VALUES IN (('seattle'), ('san francisco'), ('los angeles')), | ||
PARTITION us_east VALUES IN (('new york'), ('boston'), ('washington dc')), | ||
PARTITION europe_west VALUES IN (('amsterdam'), ('paris'), ('rome')) | ||
); | ||
ALTER PARTITION europe_west OF INDEX movr.public.rides@primary CONFIGURE ZONE USING | ||
constraints = '[+region=gcp-europe-west1]'; | ||
ALTER PARTITION us_east OF INDEX movr.public.rides@primary CONFIGURE ZONE USING | ||
constraints = '[+region=gcp-us-east1]'; | ||
ALTER PARTITION us_west OF INDEX movr.public.rides@primary CONFIGURE ZONE USING | ||
constraints = '[+region=gcp-us-west1]'; | ||
ALTER PARTITION europe_west OF INDEX movr.public.rides@rides_auto_index_fk_city_ref_users CONFIGURE ZONE USING | ||
constraints = '[+region=gcp-europe-west1]'; | ||
ALTER PARTITION us_east OF INDEX movr.public.rides@rides_auto_index_fk_city_ref_users CONFIGURE ZONE USING | ||
constraints = '[+region=gcp-us-east1]'; | ||
ALTER PARTITION us_west OF INDEX movr.public.rides@rides_auto_index_fk_city_ref_users CONFIGURE ZONE USING | ||
constraints = '[+region=gcp-us-west1]'; | ||
ALTER PARTITION europe_west OF INDEX movr.public.rides@rides_auto_index_fk_vehicle_city_ref_vehicles CONFIGURE ZONE USING | ||
constraints = '[+region=gcp-europe-west1]'; | ||
ALTER PARTITION us_east OF INDEX movr.public.rides@rides_auto_index_fk_vehicle_city_ref_vehicles CONFIGURE ZONE USING | ||
constraints = '[+region=gcp-us-east1]'; | ||
ALTER PARTITION us_west OF INDEX movr.public.rides@rides_auto_index_fk_vehicle_city_ref_vehicles CONFIGURE ZONE USING | ||
constraints = '[+region=gcp-us-west1]' | ||
; | ||
CONSTRAINT fk_city_ref_users FOREIGN KEY (rider_id) REFERENCES users(id), | ||
CONSTRAINT fk_vehicle_ref_vehicles FOREIGN KEY (vehicle_id) REFERENCES vehicles(id) | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: unindent ending There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After fixing the table (see comment below), I formatted the document with pgformatter. Should look nicer all over now. |
||
|
||
|
||
ALTER TABLE rides ADD COLUMN region crdb_internal_region AS ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we ever make this table
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My mistake. Fixed for Also, moved the |
||
CASE WHEN city = 'amsterdam' THEN 'gcp-europe-west1' | ||
WHEN city = 'paris' THEN 'gcp-europe-west1' | ||
WHEN city = 'rome' THEN 'gcp-europe-west1' | ||
WHEN city = 'new york' THEN 'gcp-us-east1' | ||
WHEN city = 'boston' THEN 'gcp-us-east1' | ||
WHEN city = 'washington dc' THEN 'gcp-us-east1' | ||
WHEN city = 'san francisco' THEN 'gcp-us-west1' | ||
WHEN city = 'seattle' THEN 'gcp-us-west1' | ||
WHEN city = 'los angeles' THEN 'gcp-us-west1' | ||
ELSE 'gcp-us-east1' | ||
END | ||
) STORED; | ||
|
||
|
||
INSERT INTO users (id, city, first_name, last_name, email, username) VALUES | ||
|
@@ -136,5 +103,5 @@ INSERT INTO users (id, city, first_name, last_name, email, username) VALUES | |
INSERT INTO vehicles (id, city, type, owner_id, date_added, status, last_location, color, brand) VALUES | ||
('142b7c9e-6227-4dbb-b188-b1dac57d5521', 'new york', 'scooter', '2804df7c-d8fd-4b1c-9799-b1d44452554b', current_date(),'available', 'Time Square', 'Blue', 'Razor'); | ||
|
||
INSERT INTO rides(city, rider_id, rider_city, vehicle_id, start_location, end_location, start_time, end_time, length) VALUES | ||
('new york', '2804df7c-d8fd-4b1c-9799-b1d44452554b', 'new york', '142b7c9e-6227-4dbb-b188-b1dac57d5521', 'Cockroach Labs, 23rd Street', 'Time Square', '2020-01-16 21:20:48.224453+00:00', '2020-01-16 21:20:52.045813+00:00', '00:00:03.82136'); | ||
INSERT INTO rides(city, rider_id, vehicle_id, start_location, end_location, start_time, end_time, length) VALUES | ||
('new york', '2804df7c-d8fd-4b1c-9799-b1d44452554b', '142b7c9e-6227-4dbb-b188-b1dac57d5521', 'Cockroach Labs, 23rd Street', 'Time Square', '2020-01-16 21:20:48.224453+00:00', '2020-01-16 21:20:52.045813+00:00', '00:00:03.82136'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the problem with this setup is that users have to ensure they set up the servers correctly, i.e. set
--locality=region=<blah>
in their flask setup. is that what we want / already have?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah ... the README and tutorial specifically instruct the user to specify the localities that match these region names. They are based on the GCP cluster names. On CC, the localities for a multi-region GCP cluster should match these names anyways.