@@ -147,8 +147,9 @@ func(dbNo DBNum) String() string {
147147type Options struct {
148148 DBNo DBNum
149149 InitIndicator string
150- TableNameSeparator string
151- KeySeparator string
150+ TableNameSeparator string //Overriden by the DB config file's separator.
151+ KeySeparator string //Overriden by the DB config file's separator.
152+ IsWriteDisabled bool //Indicated if write is allowed
152153
153154 DisableCVLCheck bool
154155}
@@ -580,18 +581,20 @@ func (d *DB) doWrite(ts * TableSpec, op _txOp, key Key, val interface{}) error {
580581 var e error = nil
581582 var value Value
582583
584+ if d .Opts .IsWriteDisabled {
585+ glog .Error ("doWrite: Write to DB disabled" )
586+ e = errors .New ("Write to DB disabled during this operation" )
587+ goto doWriteExit
588+ }
589+
583590 switch d .txState {
584591 case txStateNone :
585- if glog .V (2 ) {
586- glog .Info ("doWrite: No Transaction." )
587- }
588- break
592+ glog .Info ("doWrite: No Transaction." )
589593 case txStateWatch :
590594 if glog .V (2 ) {
591595 glog .Info ("doWrite: Change to txStateSet, txState: " , d .txState )
592596 }
593597 d .txState = txStateSet
594- break
595598 case txStateSet :
596599 if glog .V (5 ) {
597600 glog .Info ("doWrite: Remain in txStateSet, txState: " , d .txState )
@@ -653,7 +656,7 @@ func (d *DB) doWrite(ts * TableSpec, op _txOp, key Key, val interface{}) error {
653656
654657 // Transaction case.
655658
656- glog .Info ("doWrite: op: " , op , " " , key , " : " , value )
659+ glog .Info ("doWrite: op: " , op , " " , d . key2redis ( ts , key ) , " : " , value )
657660
658661 switch op {
659662 case txOpHMSet , txOpHDel :
@@ -1099,7 +1102,6 @@ func (d *DB) StartTx(w []WatchKeys, tss []*TableSpec) error {
10991102 }
11001103
11011104 var e error = nil
1102- var args []interface {}
11031105 var ret cvl.CVLRetCode
11041106
11051107 //Start CVL session
@@ -1115,6 +1117,44 @@ func (d *DB) StartTx(w []WatchKeys, tss []*TableSpec) error {
11151117 goto StartTxExit
11161118 }
11171119
1120+ e = d .performWatch (w , tss )
1121+
1122+ StartTxExit:
1123+
1124+ if glog .V (3 ) {
1125+ glog .Info ("StartTx: End: e: " , e )
1126+ }
1127+ return e
1128+ }
1129+
1130+ func (d * DB ) AppendWatchTx (w []WatchKeys , tss []* TableSpec ) error {
1131+ if glog .V (3 ) {
1132+ glog .Info ("AppendWatchTx: Begin: w: " , w , " tss: " , tss )
1133+ }
1134+
1135+ var e error = nil
1136+
1137+ // Validate State
1138+ if d .txState == txStateNone {
1139+ glog .Error ("AppendWatchTx: Incorrect State, txState: " , d .txState )
1140+ e = errors .New ("Transaction has not started" )
1141+ goto AppendWatchTxExit
1142+ }
1143+
1144+ e = d .performWatch (w , tss )
1145+
1146+ AppendWatchTxExit:
1147+
1148+ if glog .V (3 ) {
1149+ glog .Info ("AppendWatchTx: End: e: " , e )
1150+ }
1151+ return e
1152+ }
1153+
1154+ func (d * DB ) performWatch (w []WatchKeys , tss []* TableSpec ) error {
1155+ var e error
1156+ var args []interface {}
1157+
11181158 // For each watchkey
11191159 // If a pattern, Get the keys, appending results to Cmd args.
11201160 // Else append keys to the Cmd args
@@ -1133,7 +1173,7 @@ func (d *DB) StartTx(w []WatchKeys, tss []*TableSpec) error {
11331173
11341174 redisKeys , e := d .client .Keys (redisKey ).Result ()
11351175 if e != nil {
1136- glog .Warning ("StartTx : Keys: " + e .Error ())
1176+ glog .Warning ("performWatch : Keys: " + e .Error ())
11371177 continue
11381178 }
11391179 for j := 0 ; j < len (redisKeys ); j ++ {
@@ -1148,27 +1188,22 @@ func (d *DB) StartTx(w []WatchKeys, tss []*TableSpec) error {
11481188 }
11491189
11501190 if len (args ) == 1 {
1151- glog .Warning ("StartTx : Empty WatchKeys. Skipping WATCH" )
1152- goto StartTxSkipWatch
1191+ glog .Warning ("performWatch : Empty WatchKeys. Skipping WATCH" )
1192+ goto SkipWatch
11531193 }
11541194
11551195 // Issue the WATCH
11561196 _ , e = d .client .Do (args ... ).Result ()
11571197
11581198 if e != nil {
1159- glog .Warning ("StartTx : Do: WATCH " , args , " e: " , e .Error ())
1199+ glog .Warning ("performWatch : Do: WATCH " , args , " e: " , e .Error ())
11601200 }
11611201
1162- StartTxSkipWatch :
1202+ SkipWatch :
11631203
11641204 // Switch State
11651205 d .txState = txStateWatch
11661206
1167- StartTxExit:
1168-
1169- if glog .V (3 ) {
1170- glog .Info ("StartTx: End: e: " , e )
1171- }
11721207 return e
11731208}
11741209
0 commit comments