diff --git a/doc/box-protocol.txt b/doc/box-protocol.txt index d764470c37955786306b79d3e3dd0cae61c18d14..c5a4545fcdc6b535042759a077d0cfc338dec598 100644 --- a/doc/box-protocol.txt +++ b/doc/box-protocol.txt @@ -178,7 +178,9 @@ ; <offset> specifies offset in the result set, expects <uint32> value ; <limit> specifies limit in the result set, expects a <uint32> value -; <iterator> specifies the iterator type to use in search +; <iterator> specifies the iterator type to use in search, +; an integer constant from the range defined in +; https://github.com/tarantool/tarantool/blob/master/src/box/index.h#L61 ; <function_name> is used to give call path for a Lua function ; <tuple> in <update> must carry a list of update operations: diff --git a/extra/tarantool.rb b/extra/tarantool.rb index 8bdc0fe8ddd0b95d3e6fc32a4f68dd959e4a0240..26d2bb656f330f173e1f3a274ec883bef1f463fa 100644 --- a/extra/tarantool.rb +++ b/extra/tarantool.rb @@ -35,10 +35,10 @@ class Tarantool < Formula if build.with? 'debug' ENV.enable_warnings ENV.deparallelize - args << ["-DCMAKE_BUILD_TYPE=Debug"] + args << "-DCMAKE_BUILD_TYPE=Debug" ohai "Building with Debug" else - args << ["-DCMAKE_BUILD_TYPE=Release"] + args << "-DCMAKE_BUILD_TYPE=Release" ohai "Building with Release" end args << "-DENABLE_CLIENT=True" if build.stable? diff --git a/src/box/CMakeLists.txt b/src/box/CMakeLists.txt index 71da73785475f02a28187c50d7bae4e855e6be2c..bb4ad5cbca395dcda0d2081b145b04a7c7893c36 100644 --- a/src/box/CMakeLists.txt +++ b/src/box/CMakeLists.txt @@ -5,7 +5,6 @@ include_directories(${SOPHIA_INCLUDE_DIR}) set(lua_sources) lua_source(lua_sources lua/schema.lua) lua_source(lua_sources lua/box_net.lua) -lua_source(lua_sources lua/misc.lua) lua_source(lua_sources lua/tuple.lua) set(bin_sources) bin_source(bin_sources bootstrap.snap bootstrap.h) diff --git a/src/box/lua/call.cc b/src/box/lua/call.cc index 8dded68fcad7f33687911273565834f4f4f595c7..0428242fd3f294d1f9af81ebc824da7bedd63cf3 100644 --- a/src/box/lua/call.cc +++ b/src/box/lua/call.cc @@ -52,8 +52,8 @@ #include "box/schema.h" /* contents of box.lua, misc.lua, box.net.lua respectively */ -extern char schema_lua[], box_net_lua[], misc_lua[] ; -static const char *lua_sources[] = { schema_lua, box_net_lua, misc_lua, NULL }; +extern char schema_lua[], box_net_lua[]; +static const char *lua_sources[] = { schema_lua, box_net_lua, NULL }; /* * Functions, exported in box_lua.h should have prefix diff --git a/src/box/lua/misc.lua b/src/box/lua/misc.lua deleted file mode 100644 index b9172b05f7fa933283a95f970df5445303e75748..0000000000000000000000000000000000000000 --- a/src/box/lua/misc.lua +++ /dev/null @@ -1,74 +0,0 @@ --- misc.lua (internal file) - --- --- Simple counter. --- -box.counter = {} - --- --- Increment counter identified by primary key. --- Create counter if not exists. --- Returns updated value of the counter. --- -function box.counter.inc(spaceno, key) - local cnt_index = #key - local s = box.space[spaceno] - - local tuple - while true do - tuple = s:update(key, {{'+', cnt_index, 1}}) - if tuple ~= nil then break end - local data = key - table.insert(data, 1) - tuple = s:insert(data) - if tuple ~= nil then break end - end - return tuple[cnt_index] -end - --- --- Decrement counter identified by primary key. --- Delete counter if it decreased to zero. --- Returns updated value of the counter. --- -function box.counter.dec(spaceno, key) - local cnt_index = #key - local s = box.space[spaceno] - - local tuple = s:get(key) - if tuple == nil then return 0 end - if tuple[cnt_index] == 1 then - s:delete(key) - return 0 - else - tuple = s:update(key, {{'-', cnt_index, 1}}) - return tuple[cnt_index] - end -end - - --- This function automatically called by console client --- on help command. -function help() - return "server admin commands", { - "box.snapshot()", - "box.info()", - "box.stat()", - "box.slab.info()", - "box.slab.check()", - "box.fiber.info()", - "box.plugin.info()", - "box.cfg()", - "box.cfg.reload()", - "box.coredump()" - } -end - --- This function automatically called by the server for --- any new admin client. -function motd() - return "Tarantool " .. box.info.version, - "Uptime: " .. box.info.uptime -end - --- vim: set et ts=4 sts diff --git a/src/box/lua/schema.lua b/src/box/lua/schema.lua index f952c1448193eb0c6a899c517740e7f5d7ab1658..5320337f1720b88d9617078132a07e99a85a02d7 100644 --- a/src/box/lua/schema.lua +++ b/src/box/lua/schema.lua @@ -485,6 +485,46 @@ function box.schema.space.bless(space) table.insert(tuple, 1, max + 1) return space:insert(tuple) end + + -- + -- Increment counter identified by primary key. + -- Create counter if not exists. + -- Returns updated value of the counter. + -- + space_mt.inc = function(space, key) + local key = keify(key) + local cnt_index = #key + local tuple + while true do + tuple = space:update(key, {{'+', cnt_index, 1}}) + if tuple ~= nil then break end + local data = key + table.insert(data, 1) + tuple = space:insert(data) + if tuple ~= nil then break end + end + return tuple[cnt_index] + end + + -- + -- Decrement counter identified by primary key. + -- Delete counter if it decreased to zero. + -- Returns updated value of the counter. + -- + space_mt.dec = function(space, key) + local key = keify(key) + local cnt_index = #key + local tuple = space:get(key) + if tuple == nil then return 0 end + if tuple[cnt_index] == 1 then + space:delete(key) + return 0 + else + tuple = space:update(key, {{'-', cnt_index, 1}}) + return tuple[cnt_index] + end + end + space_mt.pairs = function(space, key) if space.index[0] == nil then -- empty space without indexes, return empty iterator diff --git a/src/lua/init.lua b/src/lua/init.lua index 734e7ae9517951d3ad16b02a87b3b8263f813965..ca24c82300b400d6883c97a0fb946acea8829b5d 100644 --- a/src/lua/init.lua +++ b/src/lua/init.lua @@ -27,3 +27,27 @@ dostring = function(s, ...) end return chunk(...) end + +-- This function automatically called by console client +-- on help command. +function help() + return "server admin commands", { + "box.snapshot()", + "box.info()", + "box.stat()", + "box.slab.info()", + "box.slab.check()", + "box.fiber.info()", + "box.plugin.info()", + "box.cfg()", + "box.cfg.reload()", + "box.coredump()" + } +end + +-- This function automatically called by the server for +-- any new admin client. +function motd() + return "Tarantool " .. box.info.version, + "Uptime: " .. box.info.uptime +end diff --git a/test/box/misc.result b/test/box/misc.result index 85762430ad92893e9fbfd7569f4a6ddb1f249caf..b6e031a74281772f9dace5fa5c7324534b7d6a3c 100644 --- a/test/box/misc.result +++ b/test/box/misc.result @@ -17,7 +17,6 @@ t = {} for n in pairs(box) do table.insert(t, tostring(n)) end table.sort(t) t --- - - cfg - - counter - error - index - info @@ -401,11 +400,11 @@ bit.bor(1, 2) --- - 3 ... --- A test case for box.counter +-- A test case for space:inc and space:dec space = box.space.tweedledum --- ... -box.counter.inc(space.id, {1}) +space:inc{1} --- - 1 ... @@ -413,11 +412,11 @@ space:get{1} --- - [1, 1] ... -box.counter.inc(space.id, {1}) +space:inc{1} --- - 2 ... -box.counter.inc(space.id, {1}) +space:inc{1} --- - 3 ... @@ -425,15 +424,15 @@ space:get{1} --- - [1, 3] ... -box.counter.dec(space.id, {1}) +space:dec{1} --- - 2 ... -box.counter.dec(space.id, {1}) +space:dec{1} --- - 1 ... -box.counter.dec(space.id, {1}) +space:dec{1} --- - 0 ... diff --git a/test/box/misc.test.lua b/test/box/misc.test.lua index d7dbf1b100f731cccae64d3e333fbb2be897c58f..8b7ff88588fa88d2edda430ab482c8fb1c7cb77e 100644 --- a/test/box/misc.test.lua +++ b/test/box/misc.test.lua @@ -129,16 +129,16 @@ bit.lshift(1, 32) bit.band(1, 3) bit.bor(1, 2) --- A test case for box.counter +-- A test case for space:inc and space:dec space = box.space.tweedledum -box.counter.inc(space.id, {1}) +space:inc{1} space:get{1} -box.counter.inc(space.id, {1}) -box.counter.inc(space.id, {1}) +space:inc{1} +space:inc{1} space:get{1} -box.counter.dec(space.id, {1}) -box.counter.dec(space.id, {1}) -box.counter.dec(space.id, {1}) +space:dec{1} +space:dec{1} +space:dec{1} space:get{1} space:truncate()