Skip to content

Commit 970bdf3

Browse files
committed
simplify handling of prefixes and trailing slashes
1 parent 219349f commit 970bdf3

File tree

1 file changed

+14
-81
lines changed

1 file changed

+14
-81
lines changed

docs/protocol/core/v3.0.rst

Lines changed: 14 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,41 +1137,10 @@ only one such pair for any given `key`. I.e., a store is a mapping
11371137
from keys to values. It is also assumed that keys are case sensitive,
11381138
i.e., the keys "foo" and "FOO" are different.
11391139

1140-
A store can make the following assumption on the structures of the keys it will receive:
1141-
1142-
- A key always:
1143-
- start with ``meta/``
1144-
- start with ``data/``
1145-
- is exactly ``zarr.json``.
1146-
1147-
- Most of the keys:
1148-
- start with ``meta/root``
1149-
- start with ``data/root``
1150-
1151-
- List operations ``list_dir`` will always be passed keys ending with a trailing
1152-
slash, that is to say it will only be asked to work with complete node names.
1153-
1154-
Store implementation can assume they will only be given trailing slashes, and
1155-
protocol implementation MUST pass trailing slashes to underlying stores.
1156-
1157-
For example, a store containing the following keys:
1158-
1159-
- ``meta/root/2018.group.json``
1160-
- ``meta/root/2018-01.group.json``
1161-
- ``meta/root/2018/bar.array.json``
1162-
- ``data/root/2018/bar/0.0``
1163-
1164-
The following queries are invalid:
1165-
- ``list_dir('meta/root/201')`` is invalid as ``"201"`` is not an existing node.
1166-
- ``list_dir('meta/root/2018')`` is invalid as ``"2018"`` does not ends with a ``/``,
1167-
1168-
These are valid:
1169-
- ``list_dir('meta/root/2018/')``
1170-
- ``list_dir('meta/root/2018-01/')``
1171-
1172-
This allows store implementation to avoid having to check for trailing
1173-
slashes, and avoid issues like "list_dir('meta/root/2018')" returning
1174-
values likes ``-01``
1140+
The store interface also defines some operations involving
1141+
`prefixes`. In the context of this interface, a prefix is a string
1142+
containing only characters that are valid for use in `keys` and ending
1143+
with a trailing ``/`` character.
11751144

11761145
The store operations are grouped into three sets of capabilities:
11771146
**readable**, **writeable** and **listable**. It is not necessary for
@@ -1196,15 +1165,10 @@ A **writeable store** supports the following operations:
11961165
| Parameters: `key`
11971166
| Output: none
11981167
1199-
``delete_prefix`` - Delete all keys with the given prefix from the store, include the prefix itself if it exists as a key:
1200-
1201-
| Parameter: `key`
1202-
| Output: None
1203-
1168+
``delete_prefix`` - Delete all keys with the given prefix from the store:
12041169

1205-
Clients of delete_prefix should pay attention to pass a trailing slash on
1206-
the key to delete a complete dataset or group, otherwise the store may
1207-
delete similar keys.
1170+
| Parameter: `prefix`
1171+
| Output: none
12081172
12091173
A **listable store** supports any one or more of the following
12101174
operations:
@@ -1229,50 +1193,19 @@ operations:
12291193
``list_dir`` - Retrieve all keys and prefixes with a given prefix and
12301194
which do not contain the character "/" after the given prefix.
12311195

1232-
| Parameters: `prefix`, ends with a trailing slash ``/``
1196+
| Parameters: `prefix`
12331197
| Output: set of `keys` and set of `prefixes`
12341198
12351199
For example, if a store contains the keys "a/b", "a/c", "a/d/e",
12361200
"a/f/g", then ``list_dir("a/")`` would return keys "a/b" and "a/c"
1237-
and prefixes "a/d/" and "a/f/".
1238-
1239-
On non-existing prefix, store may return the empty set.
1240-
1241-
Note: The requirement on trailing slashes is to avoid
1242-
search returning keys in the same hierarchy level but longer name, and
1243-
potentially expensive logic testing for the present of trailing slash on
1244-
each query. e.g:
1245-
1246-
- /meta/foo
1247-
- /meta/foo/dataset
1248-
- /meta/foobar
1249-
1250-
list_dir('/meta/foo') == '/meta/foo'&'/meta/foobar'
1251-
list_dir('/meta/foo/') == '/meta/foo/dataset'
1252-
1253-
Stores must return trailing slashes in key responses when those
1254-
are prefix of other keys.
1255-
1256-
Like would ``list_dir('/meta/mydir')`` returns:
1257-
- ``/meta/path1``
1258-
- ``/meta/path2``
1259-
- ``/meta/path3/``
1260-
- ``/meta/path4/``
1261-
1262-
Thus we know that ``path1``, and ``path2`` are terminal objects with data,
1263-
and that ``/meta/path3`` and ``/meta/path4``.
1264-
1265-
1266-
This is similar to ``ls -p`` on Unix systems.
1201+
and prefixes "a/d/" and "a/f/". ``list_dir("b/")`` would return
1202+
the empty set.
12671203

1268-
Note: In practice this means that this means most returned keys always ends in
1269-
``/``, ``.json``, ``.array``, ``.group``, they will otherwise be chunks
1270-
data.
12711204

1272-
Note that because keys are case sensitive, it is assumed that the operations
1273-
``set("foo", a)`` and ``set("FOO", b)`` will result in two separate (key, value)
1274-
pairs being stored. Subsequently ``get("foo")`` will return *a* and ``get("FOO")``
1275-
will return *b*.
1205+
Note that because keys are case sensitive, it is assumed that the
1206+
operations ``set("foo", a)`` and ``set("FOO", b)`` will result in two
1207+
separate (key, value) pairs being stored. Subsequently ``get("foo")``
1208+
will return *a* and ``get("FOO")`` will return *b*.
12761209

12771210

12781211
Store implementations

0 commit comments

Comments
 (0)