Write ack and read mode for linearizability on tuf_files table

Signed-off-by: Riyaz Faizullabhoy <riyaz.faizullabhoy@docker.com>
This commit is contained in:
Riyaz Faizullabhoy 2016-04-18 14:52:41 -07:00
parent 4385f46d90
commit db5d1b6fb8
3 changed files with 16 additions and 3 deletions

View File

@ -140,7 +140,7 @@ func (rdb RethinkDB) UpdateMany(gun string, updates []MetaUpdate) error {
// the given GUN and role, an error is returned.
func (rdb RethinkDB) GetCurrent(gun, role string) (created *time.Time, data []byte, err error) {
file := RDBTUFFile{}
res, err := gorethink.DB(rdb.dbName).Table(file.TableName()).GetAllByIndex(
res, err := gorethink.DB(rdb.dbName).Table(file.TableName(), gorethink.TableOpts{ReadMode: "majority"}).GetAllByIndex(
rdbGunRoleIdx, []string{gun, role},
).OrderBy(gorethink.Desc("version")).Run(rdb.sess)
if err != nil {
@ -162,7 +162,7 @@ func (rdb RethinkDB) GetCurrent(gun, role string) (created *time.Time, data []by
// not found, it returns storage.ErrNotFound
func (rdb RethinkDB) GetChecksum(gun, role, checksum string) (created *time.Time, data []byte, err error) {
var file RDBTUFFile
res, err := gorethink.DB(rdb.dbName).Table(file.TableName()).GetAllByIndex(
res, err := gorethink.DB(rdb.dbName).Table(file.TableName(), gorethink.TableOpts{ReadMode: "majority"}).GetAllByIndex(
rdbGunRoleSha256Idx, []string{gun, role, checksum},
).Run(rdb.sess)
if err != nil {

View File

@ -21,6 +21,10 @@ var (
rdbGunRoleIdx: {"gun", "role"},
rdbGunRoleSha256Idx: {"gun", "role", "sha256"},
},
// this configuration guarantees linearizability of individual atomic operations on individual documents
Config: map[string]string{
"write_acks": "majority",
},
}
keys = rethinkdb.Table{

View File

@ -33,6 +33,7 @@ type Table struct {
// on the field matching the key. Otherwise, it is a compound index
// on the list of fields in the corrensponding slice value.
SecondaryIndexes map[string][]string
Config map[string]string
}
func (t Table) term(dbName string) gorethink.Term {
@ -75,6 +76,14 @@ func (t Table) create(session *gorethink.Session, dbName string, numReplicas uin
return fmt.Errorf("unable to wait for table to be ready after reconfiguring replication: %s", err)
}
if _, err := t.term(dbName).Config().Update(t.Config).RunWrite(session); err != nil {
return fmt.Errorf("unable to configure table linearizability: %s", err)
}
if err := t.wait(session, dbName); err != nil {
return fmt.Errorf("unable to wait for table to be ready after configuring linearizability: %s", err)
}
for indexName, fieldNames := range t.SecondaryIndexes {
if len(fieldNames) == 0 {
// The field name is the index name.
@ -112,7 +121,7 @@ func (t Table) create(session *gorethink.Session, dbName string, numReplicas uin
return nil
}
// SetupDB hadles creating the database and creating all tables and indexes.
// SetupDB handles creating the database and creating all tables and indexes.
func SetupDB(session *gorethink.Session, dbName string, tables []Table) error {
if err := makeDB(session, dbName); err != nil {
return fmt.Errorf("unable to create database: %s", err)