Commit 860c4019 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent c9a3e4ad
...@@ -17,11 +17,9 @@ ...@@ -17,11 +17,9 @@
// See COPYING file for full licensing terms. // See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options. // See https://www.nexedi.com/licensing for rationale and options.
// Package neo and its children provide distributed object storage for ZODB. // Package neo provides Go implementation of NEO database.
// //
// Package neo itself provides protocol definition and common infrastructure. // TODO text
// See packages neo.client and neo.server for client and server sides respectively.
// FIXME text
package neo package neo
//go:generate gotrace gen . //go:generate gotrace gen .
......
...@@ -34,6 +34,7 @@ import ( ...@@ -34,6 +34,7 @@ import (
type Backend struct { type Backend struct {
// TODO storage layout: // TODO storage layout:
// meta/ // meta/
// meta.fs
// data/ // data/
// 1 inbox/ (commit queues) // 1 inbox/ (commit queues)
// 2 ? (data.fs) // 2 ? (data.fs)
...@@ -43,9 +44,6 @@ type Backend struct { ...@@ -43,9 +44,6 @@ type Backend struct {
// plain zodb.IStorage (e.g. loading with nextSerial) and even if // plain zodb.IStorage (e.g. loading with nextSerial) and even if
// nextSerial will be gone in the future, we will probably depend on // nextSerial will be gone in the future, we will probably depend on
// particular layout more and more -> directly work with fs1 & friends. // particular layout more and more -> directly work with fs1 & friends.
//
// TODO -> abstract into backend interfaces so various backands are
// possible (e.g. +SQL)
zstor *fs1.FileStorage // underlying ZODB storage zstor *fs1.FileStorage // underlying ZODB storage
} }
......
...@@ -25,6 +25,7 @@ import ( ...@@ -25,6 +25,7 @@ import (
"lab.nexedi.com/kirr/go123/mem" "lab.nexedi.com/kirr/go123/mem"
"lab.nexedi.com/kirr/neo/go/neo/proto"
"lab.nexedi.com/kirr/neo/go/neo/storage" "lab.nexedi.com/kirr/neo/go/neo/storage"
"lab.nexedi.com/kirr/neo/go/zodb" "lab.nexedi.com/kirr/neo/go/zodb"
...@@ -161,8 +162,10 @@ func (b *Backend) LastOid(ctx context.Context) (zodb.Oid, error) { ...@@ -161,8 +162,10 @@ func (b *Backend) LastOid(ctx context.Context) (zodb.Oid, error) {
panic("TODO") panic("TODO")
} }
func (b *Backend) Load(ctx context.Context, xid zodb.Xid) (*mem.Buf, zodb.Tid, zodb.Tid, error) { func (b *Backend) Load(ctx context.Context, xid zodb.Xid) (*proto.AnswerObject, error) {
// XXX err ctx zodb.OpError{URL: b.url, Op: "load", Err: ...} // XXX err ctx zodb.OpError{URL: b.url, Op: "load", Err: ...}
obj := &proto.AnswerObject{Oid: xid.Oid}
var data sql.RawBytes
// XXX pid = getReadablePartition (= oid % Np, raise if pid not readable) // XXX pid = getReadablePartition (= oid % Np, raise if pid not readable)
err := b.query1(ctx, err := b.query1(ctx,
...@@ -170,19 +173,26 @@ func (b *Backend) Load(ctx context.Context, xid zodb.Xid) (*mem.Buf, zodb.Tid, z ...@@ -170,19 +173,26 @@ func (b *Backend) Load(ctx context.Context, xid zodb.Xid) (*mem.Buf, zodb.Tid, z
" FROM obj LEFT JOIN data ON obj.data_id = data.id" + " FROM obj LEFT JOIN data ON obj.data_id = data.id" +
" WHERE partition=? AND oid=? AND tid<=?" + " WHERE partition=? AND oid=? AND tid<=?" +
" ORDER BY tid DESC LIMIT 1", " ORDER BY tid DESC LIMIT 1",
pid, xid.Oid, xid.At) pid, xid.Oid, xid.At).
.Scan(&serial, &compression, &hash, &data, &data_tid) Scan(&obj.Serial, &obj.Compression, &obj.Checksum, &data, &obj.DataSerial)
if err != nil { if err != nil {
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
// XXX see if object exists at all // XXX see if object exists at all
err = zodb.ErrNoData | zodb.ErrNoObject err = &zodb.NoDataError{
Oid: xid.Oid,
DeletedAt: 0, // XXX hardcoded
} }
return err err = &zodb.NoObjectError{Oid: xid.Oid}
} }
buf = return nil, err
}
// data -> obj.Data
obj.Data = mem.BufAlloc(len(data))
copy(obj.Data.Data, data)
// find out nextSerial // find out nextSerial
// XXX kill nextSerial support after neo/py cache does not need it // XXX kill nextSerial support after neo/py cache does not need it
...@@ -190,30 +200,22 @@ func (b *Backend) Load(ctx context.Context, xid zodb.Xid) (*mem.Buf, zodb.Tid, z ...@@ -190,30 +200,22 @@ func (b *Backend) Load(ctx context.Context, xid zodb.Xid) (*mem.Buf, zodb.Tid, z
"SELECT tid from obj" + "SELECT tid from obj" +
" WHERE partition=? AND oid=? AND tid>?" + " WHERE partition=? AND oid=? AND tid>?" +
" ORDER BY tid LIMIT 1", " ORDER BY tid LIMIT 1",
pid, xid.Oid, xid.At) pid, xid.Oid, xid.At).
.Scan(&nextSerial) Scan(&obj.NextSerial)
if err != nil { if err != nil {
if err == sql.ErrNoObject { if err == sql.ErrNoRows {
nextSerial = proto.INVALID_TID obj.NextSerial = proto.INVALID_TID
} else { } else {
return err return nil, err
} }
} }
return &proto.AnswerObject{ return obj, nil
Oid: xid.Oid,
Serial: serial,
NextSerial: nextSerial,
Compression: compression,
Checksum: hash,
Data: buf,
DataSerial: data_tid,
}
} }
/*
func (b *Backend) config(key string) (..., error) { func (b *Backend) config(key string) (..., error) {
// XXX cache // XXX cache
var value string var value string
...@@ -229,6 +231,7 @@ func (b *Backend) config(key string) (..., error) { ...@@ -229,6 +231,7 @@ func (b *Backend) config(key string) (..., error) {
return value, nil return value, nil
} }
*/
// ---- open by URL ---- // ---- open by URL ----
......
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