Commit 18037af1 authored by Kirill Smelkov's avatar Kirill Smelkov

go/neo/sqlite: Sync with NEO/py 1.10

There are changes in pt table and in a way last TID/OID are queried.

This corresponds to NEO/py commit b3dd6973 ("Optimize resumption of
replication by starting from a greater TID").
parent 716f683a
// Copyright (C) 2018 Nexedi SA and Contributors. // Copyright (C) 2018-2020 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com> // Kirill Smelkov <kirr@nexedi.com>
// schema & queries are based on neo/storage/database/sqlite.py // schema & queries are based on neo/storage/database/sqlite.py
// //
// This program is free software: you can Use, Study, Modify and Redistribute // This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your // it under the terms of the GNU General Public License version 3, or (at your
...@@ -67,7 +67,7 @@ import ( ...@@ -67,7 +67,7 @@ import (
// ---- schema ---- // ---- schema ----
const schemaVersion = 2 const schemaVersion = 3
// table "config" stores configuration parameters which affect the persistent data. // table "config" stores configuration parameters which affect the persistent data.
// //
...@@ -80,11 +80,11 @@ const config = ` ...@@ -80,11 +80,11 @@ const config = `
// table "pt" stores a partition table. // table "pt" stores a partition table.
const pt = ` const pt = `
rid INTEGER NOT NULL, -- row id partition INTEGER NOT NULL, -- row id
nid INTEGER NOT NULL, -- node id nid INTEGER NOT NULL, -- node id
state INTEGER NOT NULL, -- cell state tid INTEGER NOT NULL,
PRIMARY KEY (rid, nid) PRIMARY KEY (partition, nid)
` `
// table "trans" stores information on committed transactions. // table "trans" stores information on committed transactions.
...@@ -260,12 +260,10 @@ func (b *Backend) query1(query string, argv ...interface{}) *row1 { ...@@ -260,12 +260,10 @@ func (b *Backend) query1(query string, argv ...interface{}) *row1 {
func (b *Backend) LastTid(ctx context.Context) (zodb.Tid, error) { func (b *Backend) LastTid(ctx context.Context) (zodb.Tid, error) {
var lastTid zodb.Tid var lastTid zodb.Tid
// FIXME nodeID <- my node UUID err := b.query1("SELECT MAX(tid) FROM trans",
myID := proto.UUID(proto.STORAGE, 1) // FIXME + " WHERE partition=?" and caller looping over partitions from readable set
// XXX AND tid<=? (max_tid)
err := b.query1("SELECT MAX(tid) FROM pt, trans" + ).Scan(&lastTid)
" WHERE nid=? AND rid=partition" /* XXX AND tid<=? (max_tid) */,
myID).Scan(&lastTid)
if err != nil { if err != nil {
// no transaction have been committed // no transaction have been committed
...@@ -282,11 +280,9 @@ func (b *Backend) LastTid(ctx context.Context) (zodb.Tid, error) { ...@@ -282,11 +280,9 @@ func (b *Backend) LastTid(ctx context.Context) (zodb.Tid, error) {
func (b *Backend) LastOid(ctx context.Context) (zodb.Oid, error) { func (b *Backend) LastOid(ctx context.Context) (zodb.Oid, error) {
var lastOid zodb.Oid var lastOid zodb.Oid
// FIXME nodeID <- my node UUID err := b.query1("SELECT MAX(oid) FROM obj",
myID := proto.UUID(proto.STORAGE, 1) // FIXME + " WHERE `partition=?`" and caller looping over partitions from readable set
).Scan(&lastOid)
err := b.query1("SELECT MAX(oid) FROM pt, obj WHERE nid=? AND rid=partition",
myID).Scan(&lastOid)
if err != nil { if err != nil {
// no objects // no objects
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment