-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4684f47
commit 06a6dd7
Showing
11 changed files
with
348 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
fiber = require 'fiber' | ||
|
||
function reg_pollers_bootstrap() | ||
box.schema.sequence.create('reg_pollers') | ||
reg_pollers = box.schema.create_space('reg_pollers', { | ||
format = { | ||
{name = 'id', type = 'unsigned'}, | ||
{name = 'sym', type = 'STR'}, | ||
{name = 'amount', type = 'number'}, | ||
{name = 'uid', type = 'STR'}, | ||
{name = 'created', type = 'unsigned'}, | ||
{name = 'init_balance', type = 'number'}, | ||
} | ||
}) | ||
reg_pollers:create_index('primary', { | ||
sequence='reg_pollers' | ||
}) | ||
reg_pollers:create_index('by_amount', { | ||
type = 'tree', parts = { | ||
'sym', | ||
'amount' | ||
}, unique = true | ||
}) | ||
end | ||
|
||
function get_free_reg_poller(amount, sym) | ||
local rps = nil | ||
repeat | ||
if rps ~= nil then | ||
amount = amount + 1 | ||
end | ||
rps = box.space.reg_pollers.index.by_amount:select{sym, amount} | ||
until #rps == 0 | ||
return amount | ||
end | ||
|
||
function upsert_reg_poller(amount, sym, uid, init_bal) | ||
local now = fiber.clock() | ||
local rps = box.space.reg_pollers.index.by_amount:select{sym, amount} | ||
if #rps ~= 0 then | ||
local rp = rps[1] | ||
if rp['uid'] ~= uid then | ||
return { err = 'Someone already waits for such transfer.', res = nil } | ||
end | ||
if (now - rp['created']) >= 15*60 then | ||
box.space.reg_pollers:delete(rp['id']) | ||
else | ||
return { err = nil, res = rp } | ||
end | ||
end | ||
local rp = box.space.reg_pollers:insert(nil, sym, amount, uid, now, init_bal) | ||
return { err = nil, res = rp } | ||
end | ||
|
||
function delete_reg_poller(amount, sym) | ||
local rps = box.space.reg_pollers.index.by_amount:select{sym, amount} | ||
if #rps ~= 0 then | ||
local rp = rps[1] | ||
box.space.reg_pollers:delete(rp['id']) | ||
return true | ||
end | ||
return false | ||
end |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.