HTTP: databases and tables
Create, list, inspect, index, checkpoint, rename and drop databases and tables over the HTTP API, with the status codes the tests check.
A database is a directory, a table is a directory of shard logs with its own field-name registry, indexes and shard threads (dir/<database>/<table>/shard-N.log). The server starts with main.documents. Names are 1 to 64 characters of letters, digits, _ and -. All tables use the same number of shards.
Databases#
| Request | Answer |
|---|---|
GET /v1/databases | list of databases |
POST /v1/databases body {"name":"shop"} | 201; 409 if it exists; 400 for a bad name such as "bad name!" |
DELETE /v1/databases/{db} body {"confirm":"shop"} | drops it |
POST /v1/databases/{db}/rename body {"name":"new"} | renames it |
Tables#
| Request | Answer |
|---|---|
GET /v1/databases/{db}/tables | {"tables":[...]} with rows, bytes and bytes per row |
POST /v1/databases/{db}/tables body {"name":"orders"} | 201 with the table detail; 409 if it exists; 404 if the database does not exist |
GET /v1/databases/{db}/tables/{t} | detail (below); 404 if unknown |
GET .../tables/{t}/stats | {"shards":[{"documents":..,"arenaBytes":..,"garbageBytes":..}]} |
POST .../tables/{t}/indexes | create a secondary index |
POST .../tables/{t}/checkpoint | rewrite the logs now |
POST .../tables/{t}/rename | rename |
DELETE .../tables/{t} | drop |
Example sequence from databases_and_tables_can_be_created_listed_used_and_survive_a_restart:
POST /v1/databases {"name":"shop"} -> 201
POST /v1/databases {"name":"shop"} -> 409
POST /v1/databases {"name":"bad name!"} -> 400
POST /v1/databases/nope/tables {"name":"t"} -> 404
POST /v1/databases/shop/tables {"name":"orders"} -> 201
POST /v1/databases/shop/tables {"name":"customers"} -> 201
GET /v1/databases/shop/tables/orders -> "rows":"7", "columns":[...]
GET /v1/databases/shop/tables/ghost -> 404The table detail has name, database, rows, dataBytes, indexBytes, columns (name, path, types, nullable, primaryKey), indexes and primaryKey. Columns are the field names seen so far; types are not tracked yet (types is empty). rows and the sizes are strings.
Indexes#
POST /v1/databases/{db}/tables/{t}/indexes with {"field":"n","kind":"ordered"} answers {"created":true}. kind is ordered (numbers and ranges) or hash (equality). An unknown kind or a missing field is 400; GET on this path is 405. The index appears in the table detail as pk plus ix_<column> entries with kind, entries and bytes; after creating n (ordered) and tag (hash) on 200 documents, the table has three indexes and ix_n has entries 200 (test indexes_can_be_created_and_listed_over_http). Indexes are used by queries over HTTP too: {"text":"{\"n\":{\"$gte\":190}}","count":true} answers {"count":10}.
An ordered index holds numbers only; on a text column it has no entries by design, so use hash for text. The older path /v1/databases/main/collections/documents/indexes with the same body also works.
Checkpoint#
The log only grows (every overwrite and delete is a record). POST .../checkpoint stops the table, rewrites every shard log as the shortest equivalent log, reopens it, and answers {"checkpointed":..., "logBytesBefore":..., "logBytesAfter":...}. The table is unavailable meanwhile: connections on it fail and must reconnect. A server also checkpoints a shard at start when the log is at least --checkpoint-min-mb (default 8 MiB, 0 = off) and more than twice the size of its live rows.
Rename and drop#
POST .../renamewith{"name":"sales"}: rows, field names, schema and index definitions are kept. An existing name is409, an invalid one400, an unknown table404(testtables_and_databases_can_be_renamed_and_dropped_with_confirmation: after renamingorderstosales,GET .../ordersis404,GET .../salesshows"rows":"40"and still hasix_n).DELETEneeds the exact name repeated in the body,{"confirm":"sales"}. Without it the answer is400with codeconfirm_requiredand nothing happens.mainandmain.documentscannot be dropped or renamed (409).- Binary connections that used a dropped or renamed table are closed on their next request; HTTP callers get
503or404. The catalog lock is held while the table's threads stop, so other administrative calls wait briefly.
Partitioned tables#
A table created with partitions is one entry in the listing and most other operations on it are 501 for now. See Replication for table groups.
Not supported yet#
Undo or a trash folder for drops, a different shard count per table, column types in the table detail, per-table permissions.