@@ -14,6 +14,12 @@ It also provides the `crud-storage` and `crud-router` roles for
14
14
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
15
15
16
16
- [ Quickstart] ( #quickstart )
17
+ - [ Install] ( #install )
18
+ - [ Manual install] ( #manual-install )
19
+ - [ Application dependency] ( #application-dependency )
20
+ - [ Repository clone] ( #repository-clone )
21
+ - [ Usage] ( #usage )
22
+ - [ Sandbox] ( #sandbox )
17
23
- [ API] ( #api )
18
24
- [ Package info] ( #package-info )
19
25
- [ Insert] ( #insert )
@@ -44,8 +50,10 @@ It also provides the `crud-storage` and `crud-router` roles for
44
50
- [ Read view select conditions] ( #read-view-select-conditions )
45
51
- [ Read view pairs] ( #read-view-pairs )
46
52
- [ Schema] ( #schema )
53
+ - [ Tarantool 3 roles] ( #tarantool-3-roles )
54
+ - [ Usage] ( #usage-1 )
47
55
- [ Cartridge roles] ( #cartridge-roles )
48
- - [ Usage] ( #usage )
56
+ - [ Usage] ( #usage-2 )
49
57
- [ License] ( #license )
50
58
51
59
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
@@ -54,38 +62,84 @@ It also provides the `crud-storage` and `crud-router` roles for
54
62
55
63
First, [ install Tarantool] ( https://www.tarantool.io/en/download ) .
56
64
57
- Now you have the following options for learning the crud API and using it in a
58
- project:
59
-
60
- * Play with crud on a test dataset on a single instance:
61
-
62
- ``` shell
63
- $ git clone https://github.com/tarantool/crud.git
64
- $ cd crud
65
- $ tt rocks make
66
- $ ./doc/playground.lua
67
- tarantool> crud.select(' customers' , {{' <=' , ' age' , 35}}, {first = 10})
68
- tarantool> crud.select(' developers' , nil, {first = 6})
69
- ```
70
- * Install crud into the current directory:
71
-
72
- ``` shell
73
- $ tt rocks install crud
74
- ```
75
- * Add the [ crud initialization code] ( #API ) to router and storage instances
76
- initialization code for [ VShard] ( https://github.com/tarantool/vshard ) .
77
- * Add crud into dependencies of a Cartridge application and add crud roles into
78
- dependencies of your roles (see [ Cartridge roles] ( #cartridge-roles ) section).
79
- * Add crud into dependencies of your application (rockspec, RPM spec -- depends
80
- on your choice) and call crud initialization code from storage and router
81
- code (see [ API] ( #api ) section).
65
+ ### Install
66
+
67
+ #### Manual install
68
+
69
+ To try ` crud ` in your application, you may install it manually fron web
70
+ with ` tt rocks ` rock management tool.
71
+
72
+ ``` bash
73
+ tt rocks install crud
74
+ ```
75
+
76
+ #### Application dependency
77
+
78
+ To use crud in your application, set it as a rockspec dependency.
79
+
80
+ ``` lua
81
+ package = ' myapp'
82
+
83
+ version = ' scm-1'
84
+
85
+ source = {
86
+ url = ' /dev/null' ,
87
+ }
88
+
89
+ dependencies = {
90
+ ' tarantool >= 3.1.0' ,
91
+ ' crud == <the-latest-tag>-1' ,
92
+ }
93
+
94
+ build = {
95
+ type = ' none' ;
96
+ }
97
+ ```
98
+
99
+ #### Repository clone
100
+
101
+ You can also clone the repository to explore crud and try it inside a sandbox.
102
+
103
+ ``` bash
104
+ git clone https://github.com/tarantool/crud.git
105
+ cd crud
106
+ tt rocks make
107
+ ```
108
+
109
+ ### Usage
110
+
111
+ For Tarantool 3.x, enable crud roles on your application instances in a configuration
112
+ (see [ Tarantool 3 roles] ( #tarantool-3-roles ) section).
113
+ Roles support Tarantool 3.0.2, Tarantool 3.1.0 and newer.
114
+ Older versions are not supported due to
115
+ [ tarantool/tarantool #9643 ] ( https://github.com/tarantool/tarantool/issues/9643 ) and
116
+ [ tarantool/tarantool #9649 ] ( https://github.com/tarantool/tarantool/issues/9649 )
117
+ issues.
118
+
119
+ For Tarantool 1.10 and 2.x, add crud roles into dependencies of your roles
120
+ (see [ Cartridge roles] ( #cartridge-roles ) section).
121
+
122
+ For Tarantool 1.10, 2.x and 3.x you can also manually call
123
+ the [ crud initialization code] ( #api ) on [ VShard] ( https://github.com/tarantool/vshard )
124
+ router and storage instances.
125
+
126
+ ### Sandbox
127
+
128
+ The repository provide a simple sandbox application with a test dataset on a single instance.
129
+
130
+ ``` bash
131
+ ./doc/playground.lua
132
+ tarantool> crud.select(' customers' , {{' <=' , ' age' , 35}}, {first = 10})
133
+ tarantool> crud.select(' developers' , nil, {first = 6})
134
+ ```
82
135
83
136
## API
84
137
85
138
The CRUD operations should be called from router.
86
139
87
140
All VShard storages should call ` crud.init_storage() ` after
88
- ` vshard.storage.cfg() ` (or enable the ` crud-storage ` role for Cartridge)
141
+ ` vshard.storage.cfg() ` (or enable the ` roles.crud-storage ` role for Tarantool 3
142
+ or the ` crud-storage ` role for Cartridge)
89
143
first to initialize storage-side functions that are used to manipulate data
90
144
across the cluster. The storage-side functions have the same access
91
145
as a user calling ` crud.init_storage() ` . Therefore, if ` crud ` do not have
@@ -98,7 +152,8 @@ asynchronous bootstrap is used for Tarantool 3.x and
98
152
synchronous bootstrap is used for Tarantool 1.10 and 2.x.
99
153
100
154
All VShard routers should call ` crud.init_router() ` after ` vshard.router.cfg() `
101
- (or enable the ` crud-router ` role for Cartridge) to make ` crud ` functions
155
+ (or enable the ` roles.crud-storage ` role for Tarantool 3
156
+ or the ` crud-router ` role for Cartridge) to make ` crud ` functions
102
157
callable via ` net.box ` . If a user is allowed to execute ` crud ` functions on
103
158
the router-side then the user does not need additional access on storages.
104
159
@@ -1833,6 +1888,192 @@ crud.schema()
1833
1888
indexes : ...
1834
1889
```
1835
1890
1891
+ ## Tarantool 3 roles
1892
+
1893
+ ` roles.crud-storage ` is a Tarantool 3 role that initializes functions that
1894
+ are used on the storage side to perform CRUD operations. Role must be enabled
1895
+ on sharding storages.
1896
+
1897
+ ` cartridge.roles.crud-router ` is a role that exposes public ` crud ` functions
1898
+ to the global scope so that you can call them via ` net.box ` or with connectors.
1899
+ Role must be enabled on sharding routers.
1900
+
1901
+ Roles support Tarantool 3.0.2, Tarantool 3.1.0 and newer.
1902
+ Older versions are not supported due to
1903
+ [ tarantool/tarantool #9643 ] ( https://github.com/tarantool/tarantool/issues/9643 ) and
1904
+ [ tarantool/tarantool #9649 ] ( https://github.com/tarantool/tarantool/issues/9649 )
1905
+ issues.
1906
+
1907
+ ### Usage
1908
+
1909
+ 1 . Add ` crud ` to dependencies in the project rockspec.
1910
+
1911
+ ** Note** : it's better to use tagged version than ` scm-1 ` .
1912
+ Check the latest available [ release] ( https://github.com/tarantool/crud/releases ) tag and use it.
1913
+
1914
+ ``` lua
1915
+ -- <project-name>-scm-1.rockspec
1916
+ dependencies = {
1917
+ ...
1918
+ ' crud == <the-latest-tag>-1' ,
1919
+ ...
1920
+ }
1921
+ ```
1922
+
1923
+ 2. Add crud roles to your application configuration .
1924
+ Application must be a sharded one .
1925
+ It is required that ` roles.crud-storage` is enabled on each
1926
+ sharding storage .
1927
+
1928
+ ` ` ` yaml
1929
+ groups :
1930
+ routers :
1931
+ sharding :
1932
+ roles :
1933
+ - router
1934
+ roles :
1935
+ - roles .crud - router
1936
+ replicasets :
1937
+ router :
1938
+
1939
+ storages :
1940
+ sharding :
1941
+ roles :
1942
+ - storage
1943
+ roles :
1944
+ - roles .crud - storage
1945
+ replicasets :
1946
+ s - 1 :
1947
+ s - 2 :
1948
+ ```
1949
+
1950
+ <details>
1951
+ <summary> Full configuration example </ summary >
1952
+
1953
+ ` ` ` yaml
1954
+ credentials :
1955
+ users :
1956
+ replicator :
1957
+ password : replicating
1958
+ roles :
1959
+ - replication
1960
+ storage :
1961
+ password : storing - buckets
1962
+ roles :
1963
+ - sharding
1964
+ guest :
1965
+ roles :
1966
+ - super
1967
+
1968
+ sharding :
1969
+ bucket_count : 30000
1970
+
1971
+ replication :
1972
+ failover : manual
1973
+
1974
+ iproto :
1975
+ advertise :
1976
+ peer :
1977
+ login : replicator
1978
+ sharding :
1979
+ login : storage
1980
+
1981
+ groups :
1982
+ routers :
1983
+ sharding :
1984
+ roles :
1985
+ - router
1986
+ roles :
1987
+ - roles .crud - router
1988
+ replicasets :
1989
+ router :
1990
+ leader : router
1991
+ instances :
1992
+ router :
1993
+ iproto :
1994
+ listen :
1995
+ - uri : localhost :3301
1996
+ storages :
1997
+ sharding :
1998
+ roles :
1999
+ - storage
2000
+ roles :
2001
+ - roles .crud - storage
2002
+ app :
2003
+ module : mystorage
2004
+ replicasets :
2005
+ s - 1 :
2006
+ leader : s1 - master
2007
+ instances :
2008
+ s1 - master :
2009
+ iproto :
2010
+ listen :
2011
+ - uri : localhost :3302
2012
+ s1 - replica :
2013
+ iproto :
2014
+ listen :
2015
+ - uri : localhost :3303
2016
+ s - 2 :
2017
+ leader : s2 - master
2018
+ instances :
2019
+ s2 - replica :
2020
+ iproto :
2021
+ listen :
2022
+ - uri : localhost :3304
2023
+ s2 - master :
2024
+ iproto :
2025
+ listen :
2026
+ - uri : localhost :3305
2027
+ ```
2028
+ </ details >
2029
+
2030
+ 3. Set up your schema on storages (for example , through ` app.module` section in Tarantool 3 configuration .)
2031
+
2032
+ ` ` ` lua
2033
+ -- mystorage.lua
2034
+
2035
+ -- Schema setup is idempotent.
2036
+ box .watch (' box.status' , function ()
2037
+ if box .info .ro then
2038
+ return
2039
+ end
2040
+
2041
+ local customers_space = box .schema .space .create (' customers' , {
2042
+ format = {
2043
+ {name = ' id' , type = ' unsigned' },
2044
+ {name = ' bucket_id' , type = ' unsigned' },
2045
+ {name = ' name' , type = ' string' },
2046
+ {name = ' age' , type = ' number' },
2047
+ },
2048
+ if_not_exists = true ,
2049
+ })
2050
+
2051
+ customers_space :create_index (' id' , {
2052
+ parts = { {field = ' id' , is_nullable = false } },
2053
+ if_not_exists = true ,
2054
+ })
2055
+
2056
+ customers_space :create_index (' bucket_id' , {
2057
+ parts = { {field = ' bucket_id' , is_nullable = false } },
2058
+ if_not_exists = true ,
2059
+ })
2060
+
2061
+ customers_space :create_index (' age' , {
2062
+ parts = { {field = ' age' } },
2063
+ unique = false ,
2064
+ if_not_exists = true ,
2065
+ })
2066
+ end )
2067
+ ```
2068
+
2069
+ 4. Start the application cluster . You can check whether asynchronous bootstrap
2070
+ had finished through ` crud.storage_info()` calls on router .
2071
+
2072
+ Now your cluster contains storages that are configured to be used for
2073
+ CRUD - operations .
2074
+ You can simply call CRUD functions on the router to insert , select , and update
2075
+ data across the cluster .
2076
+
1836
2077
## Cartridge roles
1837
2078
1838
2079
` cartridge.roles.crud-storage` is a Tarantool Cartridge role that depends on the
0 commit comments