mirror of
https://github.com/planetmint/planetmint.git
synced 2025-06-07 06:36:38 +00:00
adjusted tarantool scripts for use in service (#383)
* adjusted tarantool scripts for use in service Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * fixed schema migrate call Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * fixed version number in changelog Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> --------- Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
parent
033235fb16
commit
461fae27d1
@ -25,6 +25,9 @@ For reference, the possible headings are:
|
|||||||
* **Known Issues**
|
* **Known Issues**
|
||||||
* **Notes**
|
* **Notes**
|
||||||
|
|
||||||
|
## [2.4.3] - 2023-17-04
|
||||||
|
* **Fixed** fixed migration behaviour for non docker service
|
||||||
|
|
||||||
## [2.4.2] - 2023-13-04
|
## [2.4.2] - 2023-13-04
|
||||||
* **Added** planetmint migration commands
|
* **Added** planetmint migration commands
|
||||||
|
|
||||||
|
@ -23,8 +23,6 @@ services:
|
|||||||
- "8081:8081"
|
- "8081:8081"
|
||||||
volumes:
|
volumes:
|
||||||
- ./planetmint/backend/tarantool/opt/init.lua:/opt/tarantool/init.lua
|
- ./planetmint/backend/tarantool/opt/init.lua:/opt/tarantool/init.lua
|
||||||
- ./planetmint/backend/tarantool/opt/functions.lua:/opt/tarantool/functions.lua
|
|
||||||
- ./planetmint/backend/tarantool/opt/migrations.lua:/opt/tarantool/migrations.lua
|
|
||||||
entrypoint: tarantool /opt/tarantool/init.lua
|
entrypoint: tarantool /opt/tarantool/init.lua
|
||||||
restart: always
|
restart: always
|
||||||
planetmint:
|
planetmint:
|
||||||
|
@ -138,20 +138,8 @@ def init_database(connection, dbname):
|
|||||||
|
|
||||||
|
|
||||||
@singledispatch
|
@singledispatch
|
||||||
def migrate_up(connection):
|
def migrate(connection):
|
||||||
"""Migrate database up
|
"""Migrate database
|
||||||
|
|
||||||
Args:
|
|
||||||
connection (:class:`~planetmint.backend.connection.Connection`): an
|
|
||||||
existing connection to use to migrate the database.
|
|
||||||
Creates one if not given.
|
|
||||||
"""
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
|
|
||||||
@singledispatch
|
|
||||||
def migrate_down(connection):
|
|
||||||
"""Migrate database down
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
connection (:class:`~planetmint.backend.connection.Connection`): an
|
connection (:class:`~planetmint.backend.connection.Connection`): an
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
local fiber = require('fiber')
|
|
||||||
|
|
||||||
local export = {}
|
|
||||||
|
|
||||||
function export.atomic(batch_size, iter, fn)
|
|
||||||
box.atomic(function()
|
|
||||||
local i = 0
|
|
||||||
for _, x in iter:unwrap() do
|
|
||||||
fn(x)
|
|
||||||
i = i + 1
|
|
||||||
if i % batch_size == 0 then
|
|
||||||
box.commit()
|
|
||||||
fiber.yield() -- for read-only operations when `commit` doesn't yield
|
|
||||||
box.begin()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
return export
|
|
@ -1,4 +1,4 @@
|
|||||||
local migrations = require('migrations')
|
local fiber = require('fiber')
|
||||||
|
|
||||||
box.cfg{listen = 3303}
|
box.cfg{listen = 3303}
|
||||||
|
|
||||||
@ -334,12 +334,64 @@ function delete_output( id )
|
|||||||
box.space.outputs:delete(id)
|
box.space.outputs:delete(id)
|
||||||
end
|
end
|
||||||
|
|
||||||
function migrate_up()
|
function atomic(batch_size, iter, fn)
|
||||||
migrations.update_utxo_13042023.up()
|
box.atomic(function()
|
||||||
-- add newer migrations below
|
local i = 0
|
||||||
|
for _, x in iter:unwrap() do
|
||||||
|
fn(x)
|
||||||
|
i = i + 1
|
||||||
|
if i % batch_size == 0 then
|
||||||
|
box.commit()
|
||||||
|
fiber.yield() -- for read-only operations when `commit` doesn't yield
|
||||||
|
box.begin()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function migrate_down()
|
function migrate()
|
||||||
-- add newer migrations above
|
-- migration code from 2.4.0 to 2.4.3
|
||||||
migrations.update_utxo_13042023.down()
|
box.once("planetmint:v2.4.3", function()
|
||||||
|
box.space.utxos:drop()
|
||||||
|
utxos = box.schema.create_space('utxos', { if_not_exists = true })
|
||||||
|
utxos:format({
|
||||||
|
{ name = 'id', type = 'string' },
|
||||||
|
{ name = 'amount' , type = 'unsigned' },
|
||||||
|
{ name = 'public_keys', type = 'array' },
|
||||||
|
{ name = 'condition', type = 'map' },
|
||||||
|
{ name = 'output_index', type = 'number' },
|
||||||
|
{ name = 'transaction_id' , type = 'string' }
|
||||||
|
})
|
||||||
|
utxos:create_index('id', {
|
||||||
|
if_not_exists = true,
|
||||||
|
parts = {{ field = 'id', type = 'string' }}
|
||||||
|
})
|
||||||
|
utxos:create_index('utxos_by_transaction_id', {
|
||||||
|
if_not_exists = true,
|
||||||
|
unique = false,
|
||||||
|
parts = {{ field = 'transaction_id', type = 'string' }}
|
||||||
|
})
|
||||||
|
utxos:create_index('utxo_by_transaction_id_and_output_index', {
|
||||||
|
if_not_exists = true,
|
||||||
|
parts = {
|
||||||
|
{ field = 'transaction_id', type = 'string' },
|
||||||
|
{ field = 'output_index', type = 'unsigned' }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
utxos:create_index('public_keys', {
|
||||||
|
if_not_exists = true,
|
||||||
|
unique = false,
|
||||||
|
parts = {{field = 'public_keys[*]', type = 'string' }}
|
||||||
|
})
|
||||||
|
|
||||||
|
atomic(1000, outputs:pairs(), function(output)
|
||||||
|
utxos:insert{output[0], output[1], output[2], output[3], output[4], output[5]}
|
||||||
|
end)
|
||||||
|
atomic(1000, utxos:pairs(), function(utxo)
|
||||||
|
spending_transaction = transactions.index.spending_transaction_by_id_and_output_index:select{utxo[5], utxo[4]}
|
||||||
|
if table.getn(spending_transaction) > 0 then
|
||||||
|
utxos:delete(utxo[0])
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end)
|
||||||
end
|
end
|
@ -1,79 +0,0 @@
|
|||||||
local functions = require('functions')
|
|
||||||
local migrations = {}
|
|
||||||
|
|
||||||
migrations.update_utxo_13042023 = {}
|
|
||||||
|
|
||||||
migrations.update_utxo_13042023.up = function()
|
|
||||||
if utxos.index.public_keys == nil then
|
|
||||||
box.space.utxos:drop()
|
|
||||||
utxos = box.schema.create_space('utxos', { if_not_exists = true })
|
|
||||||
utxos:format({
|
|
||||||
{ name = 'id', type = 'string' },
|
|
||||||
{ name = 'amount' , type = 'unsigned' },
|
|
||||||
{ name = 'public_keys', type = 'array' },
|
|
||||||
{ name = 'condition', type = 'map' },
|
|
||||||
{ name = 'output_index', type = 'number' },
|
|
||||||
{ name = 'transaction_id' , type = 'string' }
|
|
||||||
})
|
|
||||||
utxos:create_index('id', {
|
|
||||||
if_not_exists = true,
|
|
||||||
parts = {{ field = 'id', type = 'string' }}
|
|
||||||
})
|
|
||||||
utxos:create_index('utxos_by_transaction_id', {
|
|
||||||
if_not_exists = true,
|
|
||||||
unique = false,
|
|
||||||
parts = {{ field = 'transaction_id', type = 'string' }}
|
|
||||||
})
|
|
||||||
utxos:create_index('utxo_by_transaction_id_and_output_index', {
|
|
||||||
if_not_exists = true,
|
|
||||||
parts = {
|
|
||||||
{ field = 'transaction_id', type = 'string' },
|
|
||||||
{ field = 'output_index', type = 'unsigned' }
|
|
||||||
}
|
|
||||||
})
|
|
||||||
utxos:create_index('public_keys', {
|
|
||||||
if_not_exists = true,
|
|
||||||
unique = false,
|
|
||||||
parts = {{field = 'public_keys[*]', type = 'string' }}
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
outputs = box.space.outputs
|
|
||||||
functions.atomic(1000, outputs:pairs(), function(output)
|
|
||||||
utxos:insert{output[0], output[1], output[2], output[3], output[4], output[5]}
|
|
||||||
end)
|
|
||||||
functions.atomic(1000, utxos:pairs(), function(utxo)
|
|
||||||
spending_transaction = transactions.index.spending_transaction_by_id_and_output_index:select{utxo[5], utxo[4]}
|
|
||||||
if table.getn(spending_transaction) > 0 then
|
|
||||||
utxos:delete(utxo[0])
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
migrations.update_utxo_13042023.down = function()
|
|
||||||
box.space.utxos:drop()
|
|
||||||
utxos = box.schema.create_space('utxos', { if_not_exists = true })
|
|
||||||
utxos:format({
|
|
||||||
{ name = 'id', type = 'string' },
|
|
||||||
{ name = 'transaction_id', type = 'string' },
|
|
||||||
{ name = 'output_index', type = 'unsigned' },
|
|
||||||
{ name = 'utxo', type = 'map' }
|
|
||||||
})
|
|
||||||
utxos:create_index('id', {
|
|
||||||
if_not_exists = true,
|
|
||||||
parts = {{ field = 'id', type = 'string' }}
|
|
||||||
})
|
|
||||||
utxos:create_index('utxos_by_transaction_id', {
|
|
||||||
if_not_exists = true,
|
|
||||||
unique = false,
|
|
||||||
parts = {{ field = 'transaction_id', type = 'string' }}
|
|
||||||
})
|
|
||||||
utxos:create_index('utxo_by_transaction_id_and_output_index', {
|
|
||||||
if_not_exists = true,
|
|
||||||
parts = {
|
|
||||||
{ field = 'transaction_id', type = 'string' },
|
|
||||||
{ field = 'output_index', type = 'unsigned' }
|
|
||||||
}})
|
|
||||||
end
|
|
||||||
|
|
||||||
return migrations
|
|
@ -38,10 +38,5 @@ def create_tables(connection, dbname):
|
|||||||
|
|
||||||
|
|
||||||
@register_schema(TarantoolDBConnection)
|
@register_schema(TarantoolDBConnection)
|
||||||
def migrate_up(connection):
|
def migrate(connection):
|
||||||
connection.connect().call("migrate_up")
|
connection.connect().call("migrate")
|
||||||
|
|
||||||
|
|
||||||
@register_schema(TarantoolDBConnection)
|
|
||||||
def migrate_down(connection):
|
|
||||||
connection.connect().call("migrate_down")
|
|
||||||
|
@ -259,15 +259,9 @@ def run_init(args):
|
|||||||
|
|
||||||
|
|
||||||
@configure_planetmint
|
@configure_planetmint
|
||||||
def run_migrate_up(args):
|
def run_migrate(args):
|
||||||
validator = Validator()
|
validator = Validator()
|
||||||
schema.migrate_up(validator.models.connection)
|
schema.migrate(validator.models.connection)
|
||||||
|
|
||||||
|
|
||||||
@configure_planetmint
|
|
||||||
def run_migrate_down(args):
|
|
||||||
validator = Validator()
|
|
||||||
schema.migrate_up(validator.models.connection)
|
|
||||||
|
|
||||||
|
|
||||||
@configure_planetmint
|
@configure_planetmint
|
||||||
@ -377,8 +371,6 @@ def create_parser():
|
|||||||
|
|
||||||
subparsers.add_parser("migrate_up", help="Migrate up")
|
subparsers.add_parser("migrate_up", help="Migrate up")
|
||||||
|
|
||||||
subparsers.add_parser("migrate_down", help="Migrate down")
|
|
||||||
|
|
||||||
# parser for starting Planetmint
|
# parser for starting Planetmint
|
||||||
start_parser = subparsers.add_parser("start", help="Start Planetmint")
|
start_parser = subparsers.add_parser("start", help="Start Planetmint")
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "planetmint"
|
name = "planetmint"
|
||||||
version = "2.4.2"
|
version = "2.4.3"
|
||||||
description = "Planetmint: The Blockchain Database"
|
description = "Planetmint: The Blockchain Database"
|
||||||
authors = ["Planetmint contributors"]
|
authors = ["Planetmint contributors"]
|
||||||
license = "AGPLv3"
|
license = "AGPLv3"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user