github.com/geniusesgroup/libgo@v0.0.0-20220713101832-828057a9d3d4/protocol/storage-record.go (about) 1 /* For license and copyright information please see LEGAL file in repository */ 2 3 package protocol 4 5 // StorageRecords is the interface that show how an record storage work. 6 // Records are anything (such as a document or a phonograph record or a photograph) providing permanent evidence of or information about past events 7 // and equivalent to rows in RDBMS in some ways. 8 // - Record owner is one app so it must handle concurrent protection internally if not use version. 9 // Records or records or rows (RDBMS) all are same just difference in where schema must handle. 10 // Strongly think fundamentally due to all data in computer must store as k/v in storages finally even files or rows. 11 // - mediaTypeID equivalent to table name, namespace or BucketID in S3 standard, but mediaTypeID has more meaning. 12 // - version use to make StorageRecords as a "Time Series DBMS" or 13 // use to store big records with same key but in multiple part. Strongly suggest to save large record in multiple small size parts. 14 // - If need encryption, Implement requirements at block storage level. 15 type StorageRecords interface { 16 MediatypeNumbers() (num uint64, err Error) 17 ListMediatypeIDs(offset, limit uint64) (ids []uint64, err Error) 18 RecordNumbers(mediaTypeID uint64) (num uint64, err Error) 19 ListRecords(mediaTypeID uint64, offset, limit uint64) (ids [][16]byte, err Error) 20 21 // Lock works only in versioned manner. use to reach strict consistency 22 Lock(mediaTypeID uint64, id [16]byte) (lastVersion []byte, versionOffset uint64, err Error) 23 Unlock(mediaTypeID uint64, id [16]byte, newVersion []byte) (err Error) 24 25 // Count has eventual consistency behavior 26 Count(mediaTypeID uint64, id [16]byte, offset, limit uint64) (numbers uint64, err Error) 27 Length(mediaTypeID uint64, id [16]byte, versionOffset uint64) (ln int, err Error) 28 29 Get(mediaTypeID uint64, id [16]byte, versionOffset uint64) (record []byte, numbers uint64, err Error) 30 // GetLast has eventual consistency behavior 31 // GetLast(mediaTypeID uint64, id [16]byte) (record []byte, versionOffset uint64, err Error) 32 33 Save(mediaTypeID uint64, id [16]byte, record []byte, options StorageRecord_SaveOptions) (err Error) 34 Update(mediaTypeID uint64, id [16]byte, record []byte, versionOffset uint64) (err Error) 35 // make invisible just by remove from primary index for all version of record. 36 Delete(mediaTypeID uint64, id [16]byte) (err Error) 37 // make invisible just by remove from primary index. next Get() can know that a version exist, but data gone and no access to data anymore. 38 DeleteVersion(mediaTypeID uint64, id [16]byte, versionOffset uint64) (err Error) 39 40 EventTarget 41 } 42 43 type StorageRecord_SaveOptions struct { 44 // MaxVersion == StorageRecord_NoVersion means this record don't need versioning. 45 // MaxVersion > 0 indicate max version. e.g. 6 means just 6 version must store for the record. 46 // MaxVersion == StorageRecord_LastSourceVersion indicate no version limit but logically it has limit up to uint64. 47 MaxVersion uint64 48 49 // By none, hour, day, week, ... 50 PrimaryIndexSplitting uint8 51 } 52 53 const ( 54 StorageRecord_NoVersion uint64 = 0 55 StorageRecord_LastLocalVersion uint64 = 18446744073709551613 56 StorageRecord_LastEdgeVersion uint64 = 18446744073709551614 57 StorageRecord_LastSourceVersion uint64 = 18446744073709551615 58 )