2018-12-05 09:35:50 +00:00
|
|
|
// dbx.v1 golang satellitedb.dbx .
|
|
|
|
|
2019-06-05 17:06:14 +01:00
|
|
|
//--- Value Attribution ---//
|
|
|
|
model value_attribution (
|
2019-06-13 13:28:55 +01:00
|
|
|
key project_id bucket_name
|
2019-06-05 17:06:14 +01:00
|
|
|
|
2019-06-13 13:28:55 +01:00
|
|
|
field project_id blob
|
|
|
|
field bucket_name blob
|
2019-06-05 17:06:14 +01:00
|
|
|
field partner_id blob
|
2020-02-11 15:33:34 +00:00
|
|
|
field last_updated timestamp ( autoinsert, autoupdate )
|
2019-06-18 14:06:33 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
create value_attribution ()
|
|
|
|
|
|
|
|
read one (
|
|
|
|
select value_attribution
|
2019-06-19 13:02:37 +01:00
|
|
|
where value_attribution.project_id = ?
|
2019-06-19 13:50:50 +01:00
|
|
|
where value_attribution.bucket_name = ?
|
2019-06-05 17:06:14 +01:00
|
|
|
)
|
|
|
|
|
2019-05-16 15:11:15 +01:00
|
|
|
//--- containment ---//
|
|
|
|
model pending_audits (
|
|
|
|
key node_id
|
|
|
|
|
|
|
|
field node_id blob
|
|
|
|
field piece_id blob
|
|
|
|
field stripe_index int64
|
|
|
|
field share_size int64
|
|
|
|
field expected_share_hash blob
|
|
|
|
field reverify_count int64 ( updatable )
|
2019-07-18 19:08:15 +01:00
|
|
|
field path blob
|
2019-05-16 15:11:15 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
delete pending_audits ( where pending_audits.node_id = ? )
|
|
|
|
read one (
|
|
|
|
select pending_audits
|
|
|
|
where pending_audits.node_id = ?
|
|
|
|
)
|
|
|
|
|
2019-03-15 20:21:52 +00:00
|
|
|
//--- irreparableDB ---//
|
2018-12-14 14:27:21 +00:00
|
|
|
|
2018-12-10 19:08:45 +00:00
|
|
|
model irreparabledb (
|
|
|
|
key segmentpath
|
|
|
|
|
2018-12-27 21:21:50 +00:00
|
|
|
field segmentpath blob
|
|
|
|
field segmentdetail blob ( updatable )
|
|
|
|
field pieces_lost_count int64 ( updatable )
|
|
|
|
field seg_damaged_unix_sec int64 ( updatable )
|
|
|
|
field repair_attempt_count int64 ( updatable )
|
2018-12-10 19:08:45 +00:00
|
|
|
)
|
|
|
|
|
2019-09-12 18:31:50 +01:00
|
|
|
create irreparabledb ( noreturn )
|
|
|
|
update irreparabledb (
|
|
|
|
where irreparabledb.segmentpath = ?
|
|
|
|
noreturn
|
|
|
|
)
|
2018-12-10 19:08:45 +00:00
|
|
|
delete irreparabledb ( where irreparabledb.segmentpath = ? )
|
2018-12-27 21:21:50 +00:00
|
|
|
|
2018-12-10 19:08:45 +00:00
|
|
|
read one (
|
2018-12-27 21:21:50 +00:00
|
|
|
select irreparabledb
|
|
|
|
where irreparabledb.segmentpath = ?
|
2018-12-14 14:27:21 +00:00
|
|
|
)
|
|
|
|
|
2019-04-10 07:04:24 +01:00
|
|
|
read limitoffset (
|
|
|
|
select irreparabledb
|
2019-07-18 17:21:21 +01:00
|
|
|
where irreparabledb.segmentpath > ?
|
2019-04-10 07:04:24 +01:00
|
|
|
orderby asc irreparabledb.segmentpath
|
2019-03-15 20:21:52 +00:00
|
|
|
)
|
|
|
|
|
2018-12-14 14:27:21 +00:00
|
|
|
//--- accounting ---//
|
|
|
|
|
2018-12-18 17:18:42 +00:00
|
|
|
// accounting_timestamps just allows us to save the last time/thing that happened
|
|
|
|
model accounting_timestamps (
|
2018-12-27 21:21:50 +00:00
|
|
|
key name
|
2018-12-14 14:27:21 +00:00
|
|
|
|
2018-12-27 21:21:50 +00:00
|
|
|
field name text
|
|
|
|
field value timestamp ( updatable )
|
2018-12-14 14:27:21 +00:00
|
|
|
)
|
2018-12-27 21:21:50 +00:00
|
|
|
|
2019-09-12 18:31:50 +01:00
|
|
|
create accounting_timestamps ( noreturn )
|
|
|
|
update accounting_timestamps (
|
|
|
|
where accounting_timestamps.name = ?
|
|
|
|
noreturn
|
|
|
|
)
|
2018-12-27 21:21:50 +00:00
|
|
|
|
2018-12-14 14:27:21 +00:00
|
|
|
read scalar (
|
2018-12-27 21:21:50 +00:00
|
|
|
select accounting_timestamps.value
|
|
|
|
where accounting_timestamps.name = ?
|
2018-12-14 14:27:21 +00:00
|
|
|
)
|
|
|
|
|
2018-12-18 17:18:42 +00:00
|
|
|
model accounting_rollup (
|
2021-03-16 14:02:53 +00:00
|
|
|
key node_id start_time
|
2020-02-18 19:52:18 +00:00
|
|
|
index ( fields start_time )
|
|
|
|
|
2019-01-16 19:30:33 +00:00
|
|
|
field node_id blob
|
|
|
|
field start_time timestamp
|
|
|
|
field put_total int64
|
|
|
|
field get_total int64
|
|
|
|
field get_audit_total int64
|
2019-04-10 07:04:24 +01:00
|
|
|
field get_repair_total int64
|
2019-01-16 19:30:33 +00:00
|
|
|
field put_repair_total int64
|
|
|
|
field at_rest_total float64
|
2018-12-14 14:27:21 +00:00
|
|
|
)
|
|
|
|
|
2019-12-30 17:10:24 +00:00
|
|
|
//--- overlay cache ---//
|
2018-12-18 17:18:42 +00:00
|
|
|
|
2018-12-14 20:17:30 +00:00
|
|
|
model node (
|
|
|
|
key id
|
|
|
|
|
2019-06-18 10:14:31 +01:00
|
|
|
index (
|
2019-05-22 21:06:27 +01:00
|
|
|
name node_last_ip
|
2019-06-24 16:33:18 +01:00
|
|
|
fields last_net
|
2019-05-22 21:06:27 +01:00
|
|
|
)
|
|
|
|
|
2020-12-21 17:48:48 +00:00
|
|
|
index (
|
|
|
|
name nodes_dis_unk_exit_fin_last_success_index
|
|
|
|
fields disqualified unknown_audit_suspended exit_finished_at last_contact_success
|
2021-01-26 16:38:53 +00:00
|
|
|
)
|
2020-12-21 17:48:48 +00:00
|
|
|
|
2021-01-18 14:33:13 +00:00
|
|
|
field id blob
|
2020-03-06 22:04:23 +00:00
|
|
|
// address is how to contact the node, this can be a hostname or IP and it contains the port
|
2021-01-18 14:33:13 +00:00
|
|
|
field address text ( updatable, default "" ) // TODO: use compressed format
|
2020-03-06 22:04:23 +00:00
|
|
|
// last_net is the /24 subnet of the IP
|
2021-01-18 14:33:13 +00:00
|
|
|
field last_net text ( updatable )
|
|
|
|
field last_ip_port text ( updatable, nullable )
|
|
|
|
field protocol int ( updatable, default 0 )
|
|
|
|
field type int ( updatable, default 0 )
|
|
|
|
field email text ( updatable )
|
|
|
|
field wallet text ( updatable ) // TODO: use compressed format
|
|
|
|
field wallet_features text ( updatable, default "" )
|
|
|
|
field free_disk int64 ( updatable, default -1 )
|
|
|
|
field piece_count int64 ( autoinsert, updatable, default 0 )
|
2020-01-17 00:30:39 +00:00
|
|
|
|
|
|
|
field major int64 ( updatable, default 0 )
|
|
|
|
field minor int64 ( updatable, default 0 )
|
|
|
|
field patch int64 ( updatable, default 0 )
|
|
|
|
field hash text ( updatable, default "" )
|
|
|
|
field timestamp timestamp ( updatable, default "0001-01-01 00:00:00+00" )
|
|
|
|
field release bool ( updatable, default false )
|
|
|
|
|
|
|
|
field latency_90 int64 ( updatable, default 0 )
|
|
|
|
field audit_success_count int64 ( updatable, default 0 )
|
|
|
|
field total_audit_count int64 ( updatable, default 0 )
|
2020-03-18 18:40:56 +00:00
|
|
|
field vetted_at timestamp ( updatable, nullable )
|
2020-12-17 19:54:37 +00:00
|
|
|
field uptime_success_count int64 ( updatable, default 0 )
|
|
|
|
field total_uptime_count int64 ( updatable, default 0 )
|
2020-12-17 22:34:07 +00:00
|
|
|
|
2020-01-17 00:30:39 +00:00
|
|
|
field created_at timestamp ( autoinsert, default current_timestamp )
|
|
|
|
field updated_at timestamp ( autoinsert, autoupdate, default current_timestamp )
|
|
|
|
field last_contact_success timestamp ( updatable, default "epoch" )
|
|
|
|
field last_contact_failure timestamp ( updatable, default "epoch" )
|
2019-05-16 15:11:15 +01:00
|
|
|
|
2020-01-17 00:30:39 +00:00
|
|
|
field contained bool ( updatable, default false )
|
2020-02-11 21:32:50 +00:00
|
|
|
// node is disqualified when it fails too many audits or is offline for too long
|
2019-06-18 10:14:31 +01:00
|
|
|
field disqualified timestamp ( updatable, nullable )
|
2020-02-11 21:32:50 +00:00
|
|
|
// node is placed under inspection when it has too many unknown-error audits
|
|
|
|
field suspended timestamp ( updatable, nullable )
|
2020-06-09 22:49:12 +01:00
|
|
|
// renamed column from suspended
|
|
|
|
field unknown_audit_suspended timestamp ( updatable, nullable )
|
|
|
|
// node is considered unhealthy if it is offline for too many audits
|
|
|
|
field offline_suspended timestamp ( updatable, nullable )
|
|
|
|
// once a node becomes offline_suspended, mark it as under review so we check it again later
|
|
|
|
field under_review timestamp ( updatable, nullable )
|
2020-08-28 20:43:53 +01:00
|
|
|
field online_score float64 ( updatable, default 1 )
|
2019-06-18 14:45:02 +01:00
|
|
|
|
2020-02-11 21:32:50 +00:00
|
|
|
// audit_reputation_fields track information related to successful vs. failed error audits
|
2020-01-17 00:30:39 +00:00
|
|
|
field audit_reputation_alpha float64 ( updatable, default 1 )
|
|
|
|
field audit_reputation_beta float64 ( updatable, default 0 )
|
2020-02-11 21:32:50 +00:00
|
|
|
// unknown_audit_reputation fields track information related to successful vs. unknown error audits
|
|
|
|
field unknown_audit_reputation_alpha float64 ( updatable, default 1 )
|
|
|
|
field unknown_audit_reputation_beta float64 ( updatable, default 0 )
|
2019-09-13 17:57:32 +01:00
|
|
|
|
2020-02-11 15:33:34 +00:00
|
|
|
field exit_initiated_at timestamp ( updatable, nullable )
|
|
|
|
field exit_loop_completed_at timestamp ( updatable, nullable )
|
|
|
|
field exit_finished_at timestamp ( updatable, nullable )
|
2020-01-17 00:30:39 +00:00
|
|
|
field exit_success bool ( updatable, default false )
|
2018-12-14 20:17:30 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
update node ( where node.id = ? )
|
2019-09-12 18:31:50 +01:00
|
|
|
update node (
|
|
|
|
where node.id = ?
|
|
|
|
noreturn
|
|
|
|
)
|
2018-12-27 21:21:50 +00:00
|
|
|
|
2019-03-19 00:15:27 +00:00
|
|
|
// "Get" query; fails if node not found
|
2018-12-14 20:17:30 +00:00
|
|
|
read one (
|
2018-12-27 21:21:50 +00:00
|
|
|
select node
|
|
|
|
where node.id = ?
|
2018-12-14 20:17:30 +00:00
|
|
|
)
|
2018-12-17 20:14:16 +00:00
|
|
|
|
2019-01-17 18:34:13 +00:00
|
|
|
read all (
|
|
|
|
select node.id
|
|
|
|
)
|
|
|
|
|
2019-08-27 13:37:42 +01:00
|
|
|
read all (
|
|
|
|
select node.id node.piece_count
|
|
|
|
where node.piece_count != 0
|
|
|
|
)
|
|
|
|
|
2020-06-30 16:45:27 +01:00
|
|
|
//--- audit history ---//
|
|
|
|
model audit_history (
|
|
|
|
key node_id
|
|
|
|
field node_id blob
|
|
|
|
field history blob ( updatable )
|
|
|
|
)
|
|
|
|
create audit_history ()
|
|
|
|
update audit_history ( where audit_history.node_id = ? )
|
|
|
|
read one (
|
|
|
|
select audit_history
|
|
|
|
where audit_history.node_id = ?
|
|
|
|
)
|
|
|
|
|
2018-12-21 15:11:19 +00:00
|
|
|
//--- repairqueue ---//
|
|
|
|
|
|
|
|
model injuredsegment (
|
2019-04-16 19:14:09 +01:00
|
|
|
key path
|
2018-12-27 21:21:50 +00:00
|
|
|
|
2019-07-11 18:26:07 +01:00
|
|
|
field path blob
|
2019-04-16 19:14:09 +01:00
|
|
|
field data blob
|
2020-02-11 15:33:34 +00:00
|
|
|
field attempted timestamp (updatable, nullable)
|
2020-09-08 21:55:32 +01:00
|
|
|
field updated_at timestamp ( updatable, default current_timestamp )
|
2020-10-21 23:02:54 +01:00
|
|
|
field segment_health float64 (default 1)
|
2019-07-12 18:35:20 +01:00
|
|
|
|
|
|
|
index (
|
|
|
|
fields attempted
|
|
|
|
)
|
2020-02-21 21:32:05 +00:00
|
|
|
|
2020-10-21 23:02:54 +01:00
|
|
|
index (
|
|
|
|
fields segment_health
|
|
|
|
)
|
|
|
|
|
2020-09-08 21:55:32 +01:00
|
|
|
index (
|
|
|
|
fields updated_at
|
|
|
|
)
|
2018-12-21 15:11:19 +00:00
|
|
|
)
|
2018-12-27 21:21:50 +00:00
|
|
|
|
2020-09-08 21:55:32 +01:00
|
|
|
delete injuredsegment ( where injuredsegment.updated_at < ? )
|
|
|
|
|
2019-01-16 20:23:28 +00:00
|
|
|
//--- satellite console ---//
|
|
|
|
|
|
|
|
model user (
|
|
|
|
key id
|
|
|
|
|
2019-01-30 15:04:40 +00:00
|
|
|
field id blob
|
2019-06-06 17:07:14 +01:00
|
|
|
field email text ( updatable )
|
2019-09-10 15:00:33 +01:00
|
|
|
field normalized_email text ( updatable )
|
2019-03-27 12:33:32 +00:00
|
|
|
field full_name text ( updatable )
|
|
|
|
field short_name text ( updatable, nullable )
|
2019-01-30 15:04:40 +00:00
|
|
|
field password_hash blob ( updatable )
|
|
|
|
|
2019-02-11 10:33:56 +00:00
|
|
|
field status int ( updatable, autoinsert )
|
2019-07-12 18:59:19 +01:00
|
|
|
field partner_id blob ( nullable )
|
2019-01-30 15:04:40 +00:00
|
|
|
field created_at timestamp ( autoinsert )
|
2020-07-15 16:14:09 +01:00
|
|
|
field project_limit int ( updatable, default 0 )
|
2021-01-26 16:38:53 +00:00
|
|
|
|
|
|
|
field position text ( updatable, nullable )
|
|
|
|
field company_name text ( updatable, nullable )
|
|
|
|
field company_size int ( updatable, nullable )
|
|
|
|
field working_on text ( updatable, nullable )
|
|
|
|
field is_professional bool ( updatable, default false )
|
2021-02-10 15:55:38 +00:00
|
|
|
field employee_count text ( updatable, nullable )
|
2019-01-16 20:23:28 +00:00
|
|
|
)
|
2019-06-06 17:07:14 +01:00
|
|
|
|
|
|
|
create user ( )
|
|
|
|
update user ( where user.id = ? )
|
|
|
|
delete user ( where user.id = ? )
|
|
|
|
|
2019-01-16 20:23:28 +00:00
|
|
|
read one (
|
|
|
|
select user
|
2019-09-10 15:00:33 +01:00
|
|
|
where user.normalized_email = ?
|
2019-02-11 10:33:56 +00:00
|
|
|
where user.status != 0
|
2019-01-16 20:23:28 +00:00
|
|
|
)
|
|
|
|
read one (
|
|
|
|
select user
|
|
|
|
where user.id = ?
|
|
|
|
)
|
2020-07-15 16:14:09 +01:00
|
|
|
read one (
|
|
|
|
select user.project_limit
|
|
|
|
where user.id = ?
|
|
|
|
)
|
2019-01-16 20:23:28 +00:00
|
|
|
|
|
|
|
model project (
|
|
|
|
key id
|
|
|
|
|
2020-05-12 14:01:15 +01:00
|
|
|
field id blob
|
2019-01-16 20:23:28 +00:00
|
|
|
|
2020-07-06 21:28:49 +01:00
|
|
|
field name text ( updatable )
|
2020-05-12 14:01:15 +01:00
|
|
|
field description text ( updatable )
|
2020-10-06 13:50:29 +01:00
|
|
|
field usage_limit int64 ( nullable, updatable )
|
|
|
|
field bandwidth_limit int64 ( nullable, updatable )
|
2020-05-12 14:01:15 +01:00
|
|
|
field rate_limit int ( nullable, updatable )
|
2020-10-06 13:50:29 +01:00
|
|
|
field max_buckets int ( nullable, updatable )
|
2020-09-06 00:02:12 +01:00
|
|
|
field partner_id blob ( nullable )
|
2020-05-12 14:01:15 +01:00
|
|
|
field owner_id blob
|
2019-01-16 20:23:28 +00:00
|
|
|
|
2020-05-12 14:01:15 +01:00
|
|
|
field created_at timestamp ( autoinsert )
|
2019-01-16 20:23:28 +00:00
|
|
|
)
|
2019-06-06 17:07:14 +01:00
|
|
|
|
|
|
|
create project ( )
|
|
|
|
update project ( where project.id = ? )
|
|
|
|
delete project ( where project.id = ? )
|
|
|
|
|
2019-01-16 20:23:28 +00:00
|
|
|
read one (
|
|
|
|
select project
|
|
|
|
where project.id = ?
|
|
|
|
)
|
2019-12-10 16:12:49 +00:00
|
|
|
read one (
|
|
|
|
select project.usage_limit
|
|
|
|
where project.id = ?
|
|
|
|
)
|
2020-05-12 14:01:15 +01:00
|
|
|
read one (
|
|
|
|
select project.bandwidth_limit
|
|
|
|
where project.id = ?
|
|
|
|
)
|
2020-06-30 22:49:29 +01:00
|
|
|
read one (
|
|
|
|
select project.max_buckets
|
|
|
|
where project.id = ?
|
|
|
|
)
|
2020-09-09 20:20:44 +01:00
|
|
|
read one (
|
|
|
|
select project.bandwidth_limit project.usage_limit
|
|
|
|
where project.id = ?
|
|
|
|
)
|
2020-06-30 22:49:29 +01:00
|
|
|
|
2019-06-06 17:07:14 +01:00
|
|
|
read all (
|
|
|
|
select project
|
|
|
|
)
|
|
|
|
read all (
|
|
|
|
select project
|
|
|
|
where project.created_at < ?
|
|
|
|
orderby asc project.created_at
|
|
|
|
)
|
2019-11-15 14:27:44 +00:00
|
|
|
read all (
|
|
|
|
select project
|
|
|
|
where project.owner_id = ?
|
|
|
|
orderby asc project.created_at
|
|
|
|
)
|
2019-01-16 20:23:28 +00:00
|
|
|
read all (
|
|
|
|
select project
|
|
|
|
join project.id = project_member.project_id
|
|
|
|
where project_member.member_id = ?
|
|
|
|
orderby asc project.name
|
|
|
|
)
|
|
|
|
|
2019-11-05 13:16:02 +00:00
|
|
|
read limitoffset (
|
|
|
|
select project
|
|
|
|
where project.created_at < ?
|
|
|
|
orderby asc project.created_at
|
|
|
|
)
|
|
|
|
|
2019-01-16 20:23:28 +00:00
|
|
|
model project_member (
|
|
|
|
key member_id project_id
|
|
|
|
|
|
|
|
field member_id user.id cascade
|
|
|
|
field project_id project.id cascade
|
|
|
|
|
|
|
|
field created_at timestamp ( autoinsert )
|
|
|
|
)
|
|
|
|
|
2019-06-06 17:07:14 +01:00
|
|
|
create project_member ( )
|
|
|
|
delete project_member (
|
|
|
|
where project_member.member_id = ?
|
|
|
|
where project_member.project_id = ?
|
|
|
|
)
|
|
|
|
|
2019-01-16 20:23:28 +00:00
|
|
|
read all (
|
|
|
|
select project_member
|
|
|
|
where project_member.member_id = ?
|
|
|
|
)
|
|
|
|
|
|
|
|
model api_key (
|
2019-03-06 15:54:48 +00:00
|
|
|
key id
|
2019-05-24 17:51:27 +01:00
|
|
|
unique head
|
2019-01-16 20:23:28 +00:00
|
|
|
unique name project_id
|
|
|
|
|
2019-03-06 15:54:48 +00:00
|
|
|
field id blob
|
|
|
|
field project_id project.id cascade
|
2019-05-24 17:51:27 +01:00
|
|
|
field head blob
|
2019-03-06 15:54:48 +00:00
|
|
|
field name text (updatable)
|
2019-05-24 17:51:27 +01:00
|
|
|
field secret blob
|
2019-07-12 18:59:19 +01:00
|
|
|
field partner_id blob (nullable)
|
2019-03-06 15:54:48 +00:00
|
|
|
field created_at timestamp (autoinsert)
|
2019-01-16 20:23:28 +00:00
|
|
|
)
|
|
|
|
|
2019-09-12 18:31:50 +01:00
|
|
|
create api_key ( )
|
2019-12-17 20:07:54 +00:00
|
|
|
update api_key (
|
2019-09-12 18:31:50 +01:00
|
|
|
where api_key.id = ?
|
|
|
|
noreturn
|
|
|
|
)
|
2019-01-16 20:23:28 +00:00
|
|
|
delete api_key ( where api_key.id = ? )
|
|
|
|
|
|
|
|
read one (
|
|
|
|
select api_key
|
|
|
|
where api_key.id = ?
|
|
|
|
)
|
|
|
|
read one (
|
|
|
|
select api_key
|
2019-05-24 17:51:27 +01:00
|
|
|
where api_key.head = ?
|
2019-01-16 20:23:28 +00:00
|
|
|
)
|
2019-10-10 14:28:35 +01:00
|
|
|
read one (
|
|
|
|
select api_key
|
|
|
|
where api_key.name = ?
|
|
|
|
where api_key.project_id = ?
|
|
|
|
)
|
2019-02-07 19:22:49 +00:00
|
|
|
|
2019-03-28 02:46:49 +00:00
|
|
|
// --- bucket accounting tables --- //
|
2019-03-22 18:54:22 +00:00
|
|
|
|
|
|
|
model bucket_bandwidth_rollup (
|
2019-04-02 19:21:18 +01:00
|
|
|
key bucket_name project_id interval_start action
|
2020-04-21 22:09:15 +01:00
|
|
|
index (
|
|
|
|
name bucket_bandwidth_rollups_project_id_action_interval_index
|
|
|
|
fields project_id action interval_start
|
|
|
|
)
|
2020-04-17 14:04:29 +01:00
|
|
|
index (
|
|
|
|
name bucket_bandwidth_rollups_action_interval_project_id_index
|
|
|
|
fields action interval_start project_id
|
|
|
|
)
|
2019-03-22 18:54:22 +00:00
|
|
|
|
2019-04-02 19:21:18 +01:00
|
|
|
field bucket_name blob
|
|
|
|
field project_id blob
|
|
|
|
|
2020-02-11 15:33:34 +00:00
|
|
|
field interval_start timestamp
|
2019-03-22 18:54:22 +00:00
|
|
|
field interval_seconds uint
|
|
|
|
field action uint
|
|
|
|
|
2019-04-01 21:14:58 +01:00
|
|
|
field inline uint64 ( updatable )
|
|
|
|
field allocated uint64 ( updatable )
|
|
|
|
field settled uint64 ( updatable )
|
|
|
|
)
|
|
|
|
|
2020-11-30 19:34:42 +00:00
|
|
|
read paged (
|
|
|
|
select bucket_bandwidth_rollup
|
|
|
|
where bucket_bandwidth_rollup.interval_start >= ?
|
|
|
|
)
|
|
|
|
|
|
|
|
model bucket_bandwidth_rollup_archive (
|
|
|
|
key bucket_name project_id interval_start action
|
|
|
|
index (
|
|
|
|
name bucket_bandwidth_rollups_archive_project_id_action_interval_index
|
|
|
|
fields project_id action interval_start
|
|
|
|
)
|
|
|
|
index (
|
|
|
|
name bucket_bandwidth_rollups_archive_action_interval_project_id_index
|
|
|
|
fields action interval_start project_id
|
|
|
|
)
|
|
|
|
|
|
|
|
field bucket_name blob
|
|
|
|
field project_id blob
|
|
|
|
|
|
|
|
field interval_start timestamp
|
|
|
|
field interval_seconds uint
|
|
|
|
field action uint
|
|
|
|
|
|
|
|
field inline uint64 ( updatable )
|
|
|
|
field allocated uint64 ( updatable )
|
|
|
|
field settled uint64 ( updatable )
|
|
|
|
)
|
|
|
|
|
|
|
|
read paged (
|
|
|
|
select bucket_bandwidth_rollup_archive
|
|
|
|
where bucket_bandwidth_rollup_archive.interval_start >= ?
|
|
|
|
)
|
|
|
|
|
2020-06-03 14:51:02 +01:00
|
|
|
model revocation (
|
|
|
|
key revoked
|
|
|
|
field revoked blob
|
|
|
|
field api_key_id blob
|
|
|
|
)
|
|
|
|
|
|
|
|
create revocation ( noreturn )
|
|
|
|
|
2020-05-01 14:24:12 +01:00
|
|
|
model project_bandwidth_rollup (
|
|
|
|
key project_id interval_month
|
|
|
|
|
|
|
|
field project_id blob
|
|
|
|
field interval_month date
|
2020-06-03 14:51:02 +01:00
|
|
|
field egress_allocated uint64 ( updatable )
|
2020-05-01 14:24:12 +01:00
|
|
|
)
|
|
|
|
|
2019-03-28 02:46:49 +00:00
|
|
|
model bucket_storage_tally (
|
2019-04-02 19:21:18 +01:00
|
|
|
key bucket_name project_id interval_start
|
|
|
|
|
2020-12-21 16:42:00 +00:00
|
|
|
index (
|
2021-01-05 19:39:08 +00:00
|
|
|
name bucket_storage_tallies_project_id_interval_start_index
|
|
|
|
fields project_id interval_start
|
2020-12-21 16:42:00 +00:00
|
|
|
)
|
|
|
|
|
2019-04-02 19:21:18 +01:00
|
|
|
field bucket_name blob
|
|
|
|
field project_id blob
|
2019-03-22 18:54:22 +00:00
|
|
|
|
2020-02-11 15:33:34 +00:00
|
|
|
field interval_start timestamp
|
2019-03-22 18:54:22 +00:00
|
|
|
|
|
|
|
field inline uint64
|
|
|
|
field remote uint64
|
2019-04-10 07:04:24 +01:00
|
|
|
|
2019-03-28 02:46:49 +00:00
|
|
|
field remote_segments_count uint
|
|
|
|
field inline_segments_count uint
|
|
|
|
field object_count uint
|
|
|
|
|
|
|
|
field metadata_size uint64
|
2019-03-22 18:54:22 +00:00
|
|
|
)
|
|
|
|
|
2019-09-12 18:31:50 +01:00
|
|
|
create bucket_storage_tally ( noreturn )
|
2019-04-02 19:21:18 +01:00
|
|
|
|
2019-09-12 18:31:50 +01:00
|
|
|
read all (
|
|
|
|
select bucket_storage_tally
|
|
|
|
)
|
|
|
|
|
2019-04-04 15:56:20 +01:00
|
|
|
read all (
|
|
|
|
select bucket_storage_tally
|
|
|
|
where bucket_storage_tally.project_id = ?
|
|
|
|
where bucket_storage_tally.bucket_name = ?
|
|
|
|
where bucket_storage_tally.interval_start >= ?
|
|
|
|
where bucket_storage_tally.interval_start <= ?
|
|
|
|
orderby desc bucket_storage_tally.interval_start
|
|
|
|
)
|
|
|
|
|
2019-03-28 02:46:49 +00:00
|
|
|
// --- storage node accounting tables --- //
|
2019-03-22 18:54:22 +00:00
|
|
|
|
|
|
|
model storagenode_bandwidth_rollup (
|
2019-03-26 10:34:30 +00:00
|
|
|
key storagenode_id interval_start action
|
2019-03-22 18:54:22 +00:00
|
|
|
|
2020-12-21 15:37:01 +00:00
|
|
|
index (
|
|
|
|
name storagenode_bandwidth_rollups_interval_start_index
|
|
|
|
fields interval_start
|
|
|
|
)
|
|
|
|
|
2019-03-22 18:54:22 +00:00
|
|
|
field storagenode_id blob
|
2020-02-11 15:33:34 +00:00
|
|
|
field interval_start timestamp
|
2019-03-22 18:54:22 +00:00
|
|
|
field interval_seconds uint
|
|
|
|
field action uint
|
|
|
|
|
2020-01-16 01:19:10 +00:00
|
|
|
field allocated uint64 ( updatable, nullable, default 0 )
|
2019-04-01 21:14:58 +01:00
|
|
|
field settled uint64 ( updatable )
|
|
|
|
)
|
|
|
|
|
2020-06-11 19:31:45 +01:00
|
|
|
create storagenode_bandwidth_rollup()
|
|
|
|
|
|
|
|
read all (
|
|
|
|
select storagenode_bandwidth_rollup
|
|
|
|
where storagenode_bandwidth_rollup.storagenode_id = ?
|
|
|
|
where storagenode_bandwidth_rollup.interval_start = ?
|
|
|
|
)
|
|
|
|
|
2020-11-30 19:34:42 +00:00
|
|
|
read paged (
|
|
|
|
select storagenode_bandwidth_rollup
|
|
|
|
where storagenode_bandwidth_rollup.interval_start >= ?
|
|
|
|
)
|
|
|
|
|
2020-11-29 16:13:06 +00:00
|
|
|
read paged (
|
|
|
|
select storagenode_bandwidth_rollup
|
|
|
|
where storagenode_bandwidth_rollup.storagenode_id = ?
|
|
|
|
where storagenode_bandwidth_rollup.interval_start >= ?
|
|
|
|
)
|
|
|
|
|
2020-11-30 19:34:42 +00:00
|
|
|
model storagenode_bandwidth_rollup_archive (
|
|
|
|
key storagenode_id interval_start action
|
|
|
|
|
|
|
|
index (
|
|
|
|
name storagenode_bandwidth_rollup_archives_interval_start_index
|
|
|
|
fields interval_start
|
|
|
|
)
|
|
|
|
|
|
|
|
field storagenode_id blob
|
|
|
|
field interval_start timestamp
|
|
|
|
field interval_seconds uint
|
|
|
|
field action uint
|
|
|
|
|
|
|
|
field allocated uint64 ( updatable, nullable, default 0 )
|
|
|
|
field settled uint64 ( updatable )
|
|
|
|
)
|
|
|
|
|
|
|
|
read paged (
|
|
|
|
select storagenode_bandwidth_rollup_archive
|
|
|
|
where storagenode_bandwidth_rollup_archive.interval_start >= ?
|
|
|
|
)
|
|
|
|
|
2020-11-12 19:01:55 +00:00
|
|
|
///////////////////////////////////////
|
|
|
|
// orders phase2->phase3 rollout table
|
|
|
|
///////////////////////////////////////
|
|
|
|
|
|
|
|
model storagenode_bandwidth_rollup_phase2 (
|
|
|
|
table storagenode_bandwidth_rollups_phase2 // make the pluralization consistent
|
|
|
|
|
|
|
|
key storagenode_id interval_start action
|
|
|
|
|
|
|
|
field storagenode_id blob
|
|
|
|
field interval_start timestamp
|
|
|
|
field interval_seconds uint
|
|
|
|
field action uint
|
|
|
|
|
|
|
|
field allocated uint64 ( updatable, nullable, default 0 )
|
|
|
|
field settled uint64 ( updatable )
|
|
|
|
)
|
|
|
|
|
2020-11-29 16:13:06 +00:00
|
|
|
read paged (
|
|
|
|
select storagenode_bandwidth_rollup_phase2
|
|
|
|
where storagenode_bandwidth_rollup_phase2.storagenode_id = ?
|
|
|
|
where storagenode_bandwidth_rollup_phase2.interval_start >= ?
|
2020-11-12 19:01:55 +00:00
|
|
|
)
|
|
|
|
|
2019-03-28 02:46:49 +00:00
|
|
|
model storagenode_storage_tally (
|
2020-03-18 20:00:13 +00:00
|
|
|
// this primary key will enforce uniqueness on interval_end_time,node_id
|
|
|
|
// and also creates an index on interval_end_time implicitly.
|
|
|
|
// the interval_end_time will be the same value for many rows so
|
|
|
|
// we put that first so we can use cockroachdb prefix compression.
|
|
|
|
// node_id is also used many times but interval_end_time is more
|
|
|
|
// repetative and will benefit greater.
|
|
|
|
key interval_end_time node_id
|
2019-05-24 17:51:27 +01:00
|
|
|
|
2020-03-18 20:00:13 +00:00
|
|
|
index ( fields node_id )
|
|
|
|
|
|
|
|
field node_id blob
|
2019-05-10 20:05:42 +01:00
|
|
|
field interval_end_time timestamp
|
2020-03-18 20:00:13 +00:00
|
|
|
field data_total float64
|
2019-05-10 20:05:42 +01:00
|
|
|
)
|
2019-03-22 18:54:22 +00:00
|
|
|
|
2019-05-10 20:05:42 +01:00
|
|
|
read all (
|
2020-03-18 20:00:13 +00:00
|
|
|
select storagenode_storage_tally
|
2019-05-10 20:05:42 +01:00
|
|
|
)
|
2020-03-18 20:00:13 +00:00
|
|
|
|
2019-05-10 20:05:42 +01:00
|
|
|
read all (
|
2020-03-18 20:00:13 +00:00
|
|
|
select storagenode_storage_tally
|
|
|
|
where storagenode_storage_tally.interval_end_time >= ?
|
2019-03-22 18:54:22 +00:00
|
|
|
)
|
|
|
|
|
2020-02-18 19:52:18 +00:00
|
|
|
// --- storage node payment tables --- //
|
|
|
|
|
|
|
|
model storagenode_paystub (
|
|
|
|
// The (period, node_id) tuple is the primary key. The primary key index
|
|
|
|
// should serve for quick queries for all paystubs in a given period since
|
|
|
|
// it comes first but efficient queries for all paystubs with a given
|
|
|
|
// node_id will require a distinct index.
|
|
|
|
|
|
|
|
key period node_id
|
|
|
|
|
|
|
|
index ( fields node_id )
|
|
|
|
|
|
|
|
field period text // YYYY-MM, e.g. 2020-02
|
|
|
|
field node_id blob //
|
|
|
|
field created_at timestamp ( autoinsert ) //
|
|
|
|
field codes text // colon separated list
|
|
|
|
|
|
|
|
field usage_at_rest float64 // byte-hours of data at rest
|
|
|
|
field usage_get int64 // bytes of bandwidth
|
|
|
|
field usage_put int64 // bytes of bandwidth
|
|
|
|
field usage_get_repair int64 // bytes of bandwidth
|
|
|
|
field usage_put_repair int64 // bytes of bandwidth
|
|
|
|
field usage_get_audit int64 // bytes of bandwidth
|
|
|
|
|
|
|
|
field comp_at_rest int64 // in micro-units of currency
|
|
|
|
field comp_get int64 // in micro-units of currency
|
|
|
|
field comp_put int64 // in micro-units of currency
|
|
|
|
field comp_get_repair int64 // in micro-units of currency
|
|
|
|
field comp_put_repair int64 // in micro-units of currency
|
|
|
|
field comp_get_audit int64 // in micro-units of currency
|
|
|
|
|
|
|
|
field surge_percent int64 // percentage
|
|
|
|
|
2021-01-19 23:30:50 +00:00
|
|
|
field held int64 // in micro-units of currency
|
|
|
|
field owed int64 // in micro-units of currency
|
|
|
|
field disposed int64 // in micro-units of currency
|
|
|
|
field paid int64 // in micro-units of currency
|
|
|
|
field distributed int64 // in micro-units of currency
|
2020-02-18 19:52:18 +00:00
|
|
|
)
|
|
|
|
|
2021-02-10 18:40:23 +00:00
|
|
|
create storagenode_paystub ( noreturn, replace )
|
2020-02-18 19:52:18 +00:00
|
|
|
|
2021-01-15 16:23:19 +00:00
|
|
|
read one (
|
|
|
|
select storagenode_paystub
|
|
|
|
where storagenode_paystub.node_id = ?
|
|
|
|
where storagenode_paystub.period = ?
|
|
|
|
)
|
|
|
|
|
|
|
|
read all (
|
|
|
|
select storagenode_paystub
|
|
|
|
where storagenode_paystub.node_id = ?
|
|
|
|
)
|
|
|
|
|
2020-02-18 19:52:18 +00:00
|
|
|
model storagenode_payment (
|
|
|
|
key id
|
|
|
|
|
|
|
|
index ( fields node_id period )
|
|
|
|
|
|
|
|
field id serial64 //
|
|
|
|
field created_at timestamp ( autoinsert ) //
|
|
|
|
field node_id blob //
|
2020-04-01 22:58:46 +01:00
|
|
|
field period text // YYYY-MM, e.g. 2020-02
|
2020-02-18 19:52:18 +00:00
|
|
|
field amount int64 // in micro-units of currency
|
|
|
|
field receipt text ( nullable ) //
|
|
|
|
field notes text ( nullable ) //
|
|
|
|
)
|
|
|
|
|
|
|
|
create storagenode_payment ( noreturn )
|
|
|
|
|
2021-01-15 16:23:19 +00:00
|
|
|
read limitoffset (
|
|
|
|
select storagenode_payment
|
|
|
|
where storagenode_payment.node_id = ?
|
|
|
|
where storagenode_payment.period = ?
|
|
|
|
orderby desc storagenode_payment.id
|
|
|
|
)
|
|
|
|
|
|
|
|
read all (
|
|
|
|
select storagenode_payment
|
|
|
|
where storagenode_payment.node_id = ?
|
|
|
|
)
|
|
|
|
|
2021-02-10 18:40:23 +00:00
|
|
|
read all (
|
|
|
|
select storagenode_payment
|
|
|
|
where storagenode_payment.node_id = ?
|
|
|
|
where storagenode_payment.period = ?
|
|
|
|
)
|
2021-01-15 16:23:19 +00:00
|
|
|
|
2019-08-26 17:49:42 +01:00
|
|
|
//--- peer_identity ---//
|
|
|
|
|
|
|
|
model peer_identity (
|
|
|
|
key node_id
|
|
|
|
|
|
|
|
field node_id blob
|
|
|
|
field leaf_serial_number blob (updatable)
|
2019-11-05 13:16:02 +00:00
|
|
|
field chain blob (updatable) // x509 ASN.1 DER content
|
2019-08-26 17:49:42 +01:00
|
|
|
field updated_at timestamp ( autoinsert, autoupdate )
|
|
|
|
)
|
|
|
|
|
2019-09-12 18:31:50 +01:00
|
|
|
create peer_identity ( noreturn )
|
2019-08-26 17:49:42 +01:00
|
|
|
update peer_identity (
|
|
|
|
where peer_identity.node_id = ?
|
2019-09-12 18:31:50 +01:00
|
|
|
noreturn
|
2019-08-26 17:49:42 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
read one (
|
|
|
|
select peer_identity
|
|
|
|
where peer_identity.node_id = ?
|
|
|
|
)
|
|
|
|
read one (
|
|
|
|
select peer_identity.leaf_serial_number
|
|
|
|
where peer_identity.node_id = ?
|
|
|
|
)
|
|
|
|
|
2019-03-19 17:55:43 +00:00
|
|
|
//--- satellite registration token for Vanguard release (temporary table) ---//
|
|
|
|
|
|
|
|
model registration_token (
|
|
|
|
key secret
|
|
|
|
unique owner_id
|
|
|
|
|
|
|
|
field secret blob
|
|
|
|
field owner_id blob ( updatable, nullable )
|
|
|
|
|
|
|
|
field project_limit int
|
|
|
|
|
|
|
|
field created_at timestamp ( autoinsert )
|
|
|
|
)
|
|
|
|
|
|
|
|
create registration_token ( )
|
|
|
|
read one (
|
|
|
|
select registration_token
|
|
|
|
where registration_token.secret = ?
|
|
|
|
)
|
|
|
|
read one (
|
|
|
|
select registration_token
|
|
|
|
where registration_token.owner_id = ?
|
|
|
|
)
|
|
|
|
update registration_token ( where registration_token.secret = ? )
|
2019-05-13 16:53:52 +01:00
|
|
|
|
|
|
|
//--- satellite reset password token ---//
|
|
|
|
|
|
|
|
model reset_password_token (
|
|
|
|
key secret
|
|
|
|
unique owner_id
|
|
|
|
|
|
|
|
field secret blob
|
|
|
|
field owner_id blob ( updatable )
|
|
|
|
|
|
|
|
field created_at timestamp ( autoinsert )
|
|
|
|
)
|
|
|
|
|
|
|
|
create reset_password_token ( )
|
|
|
|
read one (
|
|
|
|
select reset_password_token
|
|
|
|
where reset_password_token.secret = ?
|
|
|
|
)
|
|
|
|
read one (
|
|
|
|
select reset_password_token
|
|
|
|
where reset_password_token.owner_id = ?
|
|
|
|
)
|
|
|
|
delete reset_password_token ( where reset_password_token.secret = ? )
|
2019-05-22 22:41:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
//--- offer table ---//
|
|
|
|
|
|
|
|
model offer (
|
|
|
|
key id
|
2019-06-18 10:14:31 +01:00
|
|
|
|
|
|
|
field id serial
|
2019-05-22 22:41:55 +01:00
|
|
|
field name text ( updatable )
|
|
|
|
field description text ( updatable )
|
2019-06-13 14:52:33 +01:00
|
|
|
|
2020-01-17 00:30:39 +00:00
|
|
|
field award_credit_in_cents int ( updatable, default 0 )
|
|
|
|
field invitee_credit_in_cents int ( updatable, default 0 )
|
2019-06-04 20:17:01 +01:00
|
|
|
|
2019-07-12 15:19:38 +01:00
|
|
|
field award_credit_duration_days int ( updatable, nullable )
|
|
|
|
field invitee_credit_duration_days int ( updatable, nullable )
|
2019-05-22 22:41:55 +01:00
|
|
|
|
2019-07-12 15:19:38 +01:00
|
|
|
field redeemable_cap int ( updatable, nullable )
|
2019-05-22 22:41:55 +01:00
|
|
|
|
2019-06-04 20:17:01 +01:00
|
|
|
field expires_at timestamp ( updatable )
|
2019-05-22 22:41:55 +01:00
|
|
|
field created_at timestamp ( autoinsert )
|
|
|
|
|
2019-07-08 19:39:56 +01:00
|
|
|
// status corresponds to the values of rewards.OfferStatus
|
2019-06-04 20:17:01 +01:00
|
|
|
field status int ( updatable )
|
2019-07-08 19:39:56 +01:00
|
|
|
// type corresponds to the values of rewards.OfferType
|
2019-06-04 20:17:01 +01:00
|
|
|
field type int ( updatable )
|
2019-05-22 22:41:55 +01:00
|
|
|
)
|
|
|
|
|
2019-06-13 14:52:33 +01:00
|
|
|
|
|
|
|
//--- user credit table ---//
|
|
|
|
|
|
|
|
model user_credit (
|
2019-12-17 20:07:54 +00:00
|
|
|
key id
|
|
|
|
unique id offer_id
|
2019-12-11 23:49:57 +00:00
|
|
|
index (
|
2019-12-17 20:07:54 +00:00
|
|
|
name credits_earned_user_id_offer_id
|
|
|
|
fields id offer_id
|
|
|
|
unique
|
2019-12-11 23:49:57 +00:00
|
|
|
)
|
2019-06-13 14:52:33 +01:00
|
|
|
|
2019-12-17 20:07:54 +00:00
|
|
|
field id serial
|
2019-06-13 14:52:33 +01:00
|
|
|
|
2019-12-17 20:07:54 +00:00
|
|
|
field user_id user.id cascade
|
|
|
|
field offer_id offer.id restrict
|
|
|
|
field referred_by user.id setnull ( nullable )
|
|
|
|
field type text
|
2019-06-13 14:52:33 +01:00
|
|
|
|
2019-12-17 20:07:54 +00:00
|
|
|
field credits_earned_in_cents int
|
|
|
|
field credits_used_in_cents int ( updatable, autoinsert )
|
2019-06-13 14:52:33 +01:00
|
|
|
|
2019-12-17 20:07:54 +00:00
|
|
|
field expires_at timestamp ( updatable )
|
|
|
|
field created_at timestamp ( autoinsert )
|
2019-06-13 14:52:33 +01:00
|
|
|
)
|
|
|
|
|
2019-07-01 21:45:21 +01:00
|
|
|
//--- metainfo buckets ---//
|
|
|
|
|
2019-07-03 23:03:56 +01:00
|
|
|
model bucket_metainfo (
|
2019-07-01 21:45:21 +01:00
|
|
|
key id
|
2020-06-30 22:49:29 +01:00
|
|
|
unique project_id name
|
2019-07-01 21:45:21 +01:00
|
|
|
|
|
|
|
field id blob
|
|
|
|
field project_id project.id restrict
|
|
|
|
field name blob
|
2019-07-19 16:17:34 +01:00
|
|
|
field partner_id blob (nullable, updatable)
|
2019-07-01 21:45:21 +01:00
|
|
|
|
|
|
|
field path_cipher int
|
|
|
|
|
|
|
|
field created_at timestamp ( autoinsert )
|
|
|
|
|
|
|
|
field default_segment_size int (updatable)
|
|
|
|
|
|
|
|
field default_encryption_cipher_suite int (updatable)
|
|
|
|
field default_encryption_block_size int (updatable)
|
|
|
|
|
|
|
|
field default_redundancy_algorithm int (updatable)
|
|
|
|
field default_redundancy_share_size int (updatable)
|
|
|
|
field default_redundancy_required_shares int (updatable)
|
|
|
|
field default_redundancy_repair_shares int (updatable)
|
|
|
|
field default_redundancy_optimal_shares int (updatable)
|
|
|
|
field default_redundancy_total_shares int (updatable)
|
|
|
|
)
|
|
|
|
|
2019-07-03 23:03:56 +01:00
|
|
|
create bucket_metainfo ()
|
2019-07-19 16:17:34 +01:00
|
|
|
update bucket_metainfo (
|
|
|
|
where bucket_metainfo.project_id = ?
|
|
|
|
where bucket_metainfo.name = ?
|
|
|
|
)
|
2019-07-01 21:45:21 +01:00
|
|
|
|
|
|
|
read one (
|
2019-07-03 23:03:56 +01:00
|
|
|
select bucket_metainfo
|
|
|
|
where bucket_metainfo.project_id = ?
|
|
|
|
where bucket_metainfo.name = ?
|
2019-07-01 21:45:21 +01:00
|
|
|
)
|
|
|
|
|
2020-06-25 15:47:44 +01:00
|
|
|
read one (
|
|
|
|
select bucket_metainfo.id
|
|
|
|
where bucket_metainfo.project_id = ?
|
|
|
|
where bucket_metainfo.name = ?
|
|
|
|
)
|
|
|
|
|
2019-07-03 23:03:56 +01:00
|
|
|
delete bucket_metainfo (
|
|
|
|
where bucket_metainfo.project_id = ?
|
|
|
|
where bucket_metainfo.name = ?
|
2019-07-01 21:45:21 +01:00
|
|
|
)
|
2019-07-08 23:32:18 +01:00
|
|
|
|
|
|
|
read limitoffset ( // Forward
|
|
|
|
select bucket_metainfo
|
|
|
|
where bucket_metainfo.project_id = ?
|
|
|
|
where bucket_metainfo.name >= ?
|
|
|
|
orderby asc bucket_metainfo.name
|
|
|
|
)
|
2019-07-12 13:57:02 +01:00
|
|
|
|
|
|
|
read limitoffset ( // After
|
|
|
|
select bucket_metainfo
|
|
|
|
where bucket_metainfo.project_id = ?
|
|
|
|
where bucket_metainfo.name > ?
|
|
|
|
orderby asc bucket_metainfo.name
|
|
|
|
)
|
2019-09-13 17:57:32 +01:00
|
|
|
|
2020-06-30 22:49:29 +01:00
|
|
|
read count (
|
|
|
|
select bucket_metainfo.name
|
|
|
|
where bucket_metainfo.project_id = ?
|
|
|
|
)
|
|
|
|
|
2019-09-13 17:57:32 +01:00
|
|
|
//--- graceful exit progress ---//
|
|
|
|
|
|
|
|
model graceful_exit_progress (
|
|
|
|
table graceful_exit_progress
|
2020-01-17 00:30:39 +00:00
|
|
|
key node_id
|
2019-09-13 17:57:32 +01:00
|
|
|
|
2020-01-17 00:30:39 +00:00
|
|
|
field node_id blob
|
|
|
|
field bytes_transferred int64 ( updatable )
|
|
|
|
field pieces_transferred int64 ( autoinsert, updatable, default 0 )
|
|
|
|
field pieces_failed int64 ( autoinsert, updatable, default 0 )
|
|
|
|
field updated_at timestamp ( autoinsert, autoupdate )
|
2019-09-13 17:57:32 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
read one (
|
|
|
|
select graceful_exit_progress
|
2019-11-05 13:16:02 +00:00
|
|
|
where graceful_exit_progress.node_id = ?
|
2019-09-13 17:57:32 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
//--- graceful exit transfer queue ---//
|
|
|
|
|
|
|
|
model graceful_exit_transfer_queue (
|
|
|
|
table graceful_exit_transfer_queue
|
2020-01-17 00:30:39 +00:00
|
|
|
key node_id path piece_num
|
|
|
|
|
|
|
|
field node_id blob
|
|
|
|
field path blob
|
|
|
|
field piece_num int
|
|
|
|
field root_piece_id blob ( nullable )
|
|
|
|
field durability_ratio float64 ( updatable )
|
|
|
|
field queued_at timestamp ( autoinsert )
|
|
|
|
field requested_at timestamp ( updatable, nullable )
|
|
|
|
field last_failed_at timestamp ( updatable, nullable )
|
|
|
|
field last_failed_code int ( updatable, nullable )
|
|
|
|
field failed_count int ( updatable, nullable )
|
|
|
|
field finished_at timestamp ( updatable, nullable )
|
|
|
|
field order_limit_send_count int ( updatable, default 0 )
|
Add index to graceful_exit_transfer_queue table
This fixes a slow query that was taking up to 4 seconds in production
SELECT node_id, path, piece_num, root_piece_id, durability_ratio, queued_at, requested_at, last_failed_at, last_failed_code, failed_count, finished_at, order_limit_send_count
FROM graceful_exit_transfer_queue
WHERE node_id = '[redacted]'
AND finished_at is NULL
AND last_failed_at is NULL
ORDER BY durability_ratio asc, queued_at asc LIMIT 300 OFFSET 0;
Change-Id: Ib89743ca35f1d8d0a1456b20fa08c683ebdc1549
2020-10-23 18:54:45 +01:00
|
|
|
|
|
|
|
index (
|
|
|
|
name graceful_exit_transfer_queue_nid_dr_qa_fa_lfa_index
|
|
|
|
fields node_id durability_ratio queued_at finished_at last_failed_at
|
|
|
|
)
|
2019-09-13 17:57:32 +01:00
|
|
|
)
|
|
|
|
|
2019-11-05 13:16:02 +00:00
|
|
|
update graceful_exit_transfer_queue (
|
2019-09-13 17:57:32 +01:00
|
|
|
where graceful_exit_transfer_queue.node_id = ?
|
|
|
|
where graceful_exit_transfer_queue.path = ?
|
2019-10-28 15:08:33 +00:00
|
|
|
where graceful_exit_transfer_queue.piece_num = ?
|
2019-09-13 17:57:32 +01:00
|
|
|
noreturn
|
|
|
|
)
|
2019-11-05 13:16:02 +00:00
|
|
|
delete graceful_exit_transfer_queue (
|
2019-09-13 17:57:32 +01:00
|
|
|
where graceful_exit_transfer_queue.node_id = ?
|
|
|
|
)
|
|
|
|
|
2019-11-05 13:16:02 +00:00
|
|
|
delete graceful_exit_transfer_queue (
|
2019-09-13 17:57:32 +01:00
|
|
|
where graceful_exit_transfer_queue.node_id = ?
|
|
|
|
where graceful_exit_transfer_queue.path = ?
|
2019-10-28 15:08:33 +00:00
|
|
|
where graceful_exit_transfer_queue.piece_num = ?
|
2019-09-13 17:57:32 +01:00
|
|
|
)
|
2019-09-25 18:12:44 +01:00
|
|
|
|
2019-11-05 13:16:02 +00:00
|
|
|
delete graceful_exit_transfer_queue (
|
2019-09-25 18:12:44 +01:00
|
|
|
where graceful_exit_transfer_queue.node_id = ?
|
|
|
|
where graceful_exit_transfer_queue.finished_at != null
|
|
|
|
)
|
|
|
|
|
2019-11-05 13:16:02 +00:00
|
|
|
read one (
|
2019-09-13 17:57:32 +01:00
|
|
|
select graceful_exit_transfer_queue
|
|
|
|
where graceful_exit_transfer_queue.node_id = ?
|
|
|
|
where graceful_exit_transfer_queue.path = ?
|
2019-10-28 15:08:33 +00:00
|
|
|
where graceful_exit_transfer_queue.piece_num = ?
|
2019-09-13 17:57:32 +01:00
|
|
|
)
|
2019-10-10 18:12:23 +01:00
|
|
|
|
|
|
|
//--- satellite payments ---//
|
|
|
|
|
2019-10-15 19:05:45 +01:00
|
|
|
model stripe_customer (
|
2019-10-10 18:12:23 +01:00
|
|
|
key user_id
|
|
|
|
unique customer_id
|
|
|
|
|
|
|
|
field user_id blob
|
|
|
|
field customer_id text
|
|
|
|
field created_at timestamp ( autoinsert )
|
|
|
|
)
|
|
|
|
|
2019-10-15 19:05:45 +01:00
|
|
|
create stripe_customer ( )
|
2019-11-05 13:16:02 +00:00
|
|
|
|
2019-10-11 16:00:35 +01:00
|
|
|
read one (
|
2019-10-15 19:05:45 +01:00
|
|
|
select stripe_customer.customer_id
|
|
|
|
where stripe_customer.user_id = ?
|
2019-10-17 15:04:50 +01:00
|
|
|
)
|
2019-11-05 13:16:02 +00:00
|
|
|
read limitoffset (
|
|
|
|
select stripe_customer
|
|
|
|
where stripe_customer.created_at <= ?
|
|
|
|
orderby desc stripe_customer.created_at
|
|
|
|
)
|
2019-10-17 15:04:50 +01:00
|
|
|
|
|
|
|
model coinpayments_transaction (
|
|
|
|
key id
|
|
|
|
|
2019-11-15 14:59:39 +00:00
|
|
|
field id text
|
|
|
|
field user_id blob
|
|
|
|
field address text
|
|
|
|
field amount blob
|
|
|
|
field received blob ( updatable )
|
|
|
|
field status int ( updatable )
|
|
|
|
field key text
|
|
|
|
field timeout int
|
2019-10-17 15:04:50 +01:00
|
|
|
|
|
|
|
field created_at timestamp ( autoinsert )
|
|
|
|
)
|
|
|
|
|
|
|
|
create coinpayments_transaction ()
|
2019-10-23 13:04:54 +01:00
|
|
|
update coinpayments_transaction ( where coinpayments_transaction.id = ? )
|
|
|
|
|
2019-11-12 11:14:34 +00:00
|
|
|
read all (
|
|
|
|
select coinpayments_transaction
|
|
|
|
where coinpayments_transaction.user_id = ?
|
|
|
|
orderby desc coinpayments_transaction.created_at
|
|
|
|
)
|
2019-10-29 16:04:34 +00:00
|
|
|
|
|
|
|
model stripecoinpayments_apply_balance_intent (
|
|
|
|
key tx_id
|
|
|
|
|
|
|
|
field tx_id coinpayments_transaction.id cascade
|
|
|
|
field state int ( updatable )
|
|
|
|
|
|
|
|
field created_at timestamp ( autoinsert )
|
|
|
|
)
|
|
|
|
|
2019-11-05 13:16:02 +00:00
|
|
|
model stripecoinpayments_invoice_project_record (
|
|
|
|
key id
|
|
|
|
|
|
|
|
unique project_id period_start period_end
|
|
|
|
|
|
|
|
field id blob
|
|
|
|
field project_id blob
|
|
|
|
field storage float64
|
|
|
|
field egress int64
|
|
|
|
field objects int64
|
|
|
|
field period_start timestamp
|
|
|
|
field period_end timestamp
|
|
|
|
field state int ( updatable )
|
|
|
|
|
|
|
|
field created_at timestamp ( autoinsert )
|
|
|
|
)
|
|
|
|
|
|
|
|
create stripecoinpayments_invoice_project_record ()
|
|
|
|
update stripecoinpayments_invoice_project_record (
|
|
|
|
where stripecoinpayments_invoice_project_record.id = ?
|
|
|
|
)
|
|
|
|
read one (
|
|
|
|
select stripecoinpayments_invoice_project_record
|
|
|
|
where stripecoinpayments_invoice_project_record.project_id = ?
|
|
|
|
where stripecoinpayments_invoice_project_record.period_start = ?
|
|
|
|
where stripecoinpayments_invoice_project_record.period_end = ?
|
|
|
|
)
|
|
|
|
read limitoffset (
|
|
|
|
select stripecoinpayments_invoice_project_record
|
2020-05-12 09:46:48 +01:00
|
|
|
where stripecoinpayments_invoice_project_record.period_start = ?
|
|
|
|
where stripecoinpayments_invoice_project_record.period_end = ?
|
2019-11-05 13:16:02 +00:00
|
|
|
where stripecoinpayments_invoice_project_record.state = ?
|
|
|
|
)
|
2019-11-15 14:59:39 +00:00
|
|
|
|
|
|
|
model stripecoinpayments_tx_conversion_rate (
|
|
|
|
key tx_id
|
|
|
|
|
|
|
|
field tx_id text
|
|
|
|
field rate blob
|
|
|
|
|
|
|
|
field created_at timestamp ( autoinsert )
|
|
|
|
)
|
|
|
|
|
|
|
|
create stripecoinpayments_tx_conversion_rate ()
|
|
|
|
|
|
|
|
read one (
|
|
|
|
select stripecoinpayments_tx_conversion_rate
|
|
|
|
where stripecoinpayments_tx_conversion_rate.tx_id = ?
|
|
|
|
)
|
2019-11-26 17:58:51 +00:00
|
|
|
|
2021-03-03 23:16:28 +00:00
|
|
|
model coupon_code (
|
|
|
|
key id
|
|
|
|
unique name
|
|
|
|
|
|
|
|
field id blob
|
|
|
|
field name text
|
|
|
|
field amount int64
|
|
|
|
field description text
|
|
|
|
field type int
|
|
|
|
field duration int64
|
|
|
|
|
|
|
|
field created_at timestamp ( autoinsert )
|
|
|
|
)
|
|
|
|
|
|
|
|
create coupon_code ()
|
|
|
|
delete coupon_code (
|
|
|
|
where coupon_code.name = ?
|
|
|
|
)
|
|
|
|
read one (
|
|
|
|
select coupon_code
|
|
|
|
where coupon_code.name = ?
|
|
|
|
)
|
|
|
|
|
2019-11-26 17:58:51 +00:00
|
|
|
model coupon (
|
|
|
|
key id
|
|
|
|
|
|
|
|
field id blob
|
|
|
|
field user_id blob
|
|
|
|
field amount int64
|
|
|
|
field description text
|
2020-01-07 10:41:19 +00:00
|
|
|
field type int
|
2019-11-26 17:58:51 +00:00
|
|
|
field status int ( updatable )
|
|
|
|
field duration int64
|
2021-03-03 23:16:28 +00:00
|
|
|
field coupon_code_name text ( nullable )
|
2019-11-26 17:58:51 +00:00
|
|
|
|
|
|
|
field created_at timestamp ( autoinsert )
|
|
|
|
)
|
|
|
|
|
|
|
|
create coupon ()
|
|
|
|
update coupon (
|
|
|
|
where coupon.id = ?
|
|
|
|
)
|
|
|
|
delete coupon (
|
|
|
|
where coupon.id = ?
|
|
|
|
)
|
2020-01-07 10:41:19 +00:00
|
|
|
read one (
|
|
|
|
select coupon
|
|
|
|
where coupon.id = ?
|
|
|
|
)
|
2019-11-26 17:58:51 +00:00
|
|
|
read all (
|
|
|
|
select coupon
|
|
|
|
where coupon.user_id = ?
|
|
|
|
orderby desc coupon.created_at
|
|
|
|
)
|
2020-01-07 10:41:19 +00:00
|
|
|
read all (
|
|
|
|
select coupon
|
|
|
|
where coupon.user_id = ?
|
|
|
|
where coupon.status = ?
|
|
|
|
orderby desc coupon.created_at
|
|
|
|
)
|
2019-11-26 17:58:51 +00:00
|
|
|
read all (
|
|
|
|
select coupon
|
|
|
|
where coupon.status = ?
|
|
|
|
orderby desc coupon.created_at
|
|
|
|
)
|
|
|
|
read limitoffset (
|
|
|
|
select coupon
|
|
|
|
where coupon.created_at <= ?
|
|
|
|
where coupon.status = ?
|
|
|
|
orderby desc coupon.created_at
|
|
|
|
)
|
|
|
|
model coupon_usage (
|
2020-01-07 10:41:19 +00:00
|
|
|
key coupon_id period
|
2019-11-26 17:58:51 +00:00
|
|
|
|
2020-01-07 10:41:19 +00:00
|
|
|
field coupon_id blob
|
|
|
|
field amount int64
|
|
|
|
field status int ( updatable )
|
|
|
|
field period timestamp
|
2019-11-26 17:58:51 +00:00
|
|
|
)
|
|
|
|
create coupon_usage ()
|
2020-01-07 10:41:19 +00:00
|
|
|
read limitoffset (
|
|
|
|
select coupon_usage
|
2020-05-12 09:46:48 +01:00
|
|
|
where coupon_usage.period = ?
|
2020-01-07 10:41:19 +00:00
|
|
|
where coupon_usage.status = 0
|
|
|
|
)
|
|
|
|
update coupon_usage (
|
|
|
|
where coupon_usage.coupon_id = ?
|
|
|
|
where coupon_usage.period = ?
|
|
|
|
)
|
2020-01-24 13:38:53 +00:00
|
|
|
|
2020-07-01 16:25:20 +01:00
|
|
|
// -- node api version -- //
|
|
|
|
|
|
|
|
model node_api_version (
|
|
|
|
key id
|
|
|
|
|
|
|
|
field id blob
|
|
|
|
field api_version int ( updatable )
|
|
|
|
|
|
|
|
field created_at timestamp ( autoinsert )
|
|
|
|
field updated_at timestamp ( autoinsert, autoupdate )
|
|
|
|
)
|
|
|
|
|
|
|
|
create node_api_version (
|
|
|
|
noreturn
|
|
|
|
replace
|
|
|
|
)
|
|
|
|
|
|
|
|
read has (
|
|
|
|
select node_api_version
|
|
|
|
where node_api_version.id = ?
|
|
|
|
where node_api_version.api_version >= ?
|
|
|
|
)
|
|
|
|
|
|
|
|
update node_api_version (
|
|
|
|
where node_api_version.id = ?
|
|
|
|
where node_api_version.api_version < ?
|
|
|
|
noreturn
|
|
|
|
)
|