@@ -147,8 +147,9 @@ func(dbNo DBNum) String() string {
147
147
type Options struct {
148
148
DBNo DBNum
149
149
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
152
153
153
154
DisableCVLCheck bool
154
155
}
@@ -580,18 +581,20 @@ func (d *DB) doWrite(ts * TableSpec, op _txOp, key Key, val interface{}) error {
580
581
var e error = nil
581
582
var value Value
582
583
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
+
583
590
switch d .txState {
584
591
case txStateNone :
585
- if glog .V (2 ) {
586
- glog .Info ("doWrite: No Transaction." )
587
- }
588
- break
592
+ glog .Info ("doWrite: No Transaction." )
589
593
case txStateWatch :
590
594
if glog .V (2 ) {
591
595
glog .Info ("doWrite: Change to txStateSet, txState: " , d .txState )
592
596
}
593
597
d .txState = txStateSet
594
- break
595
598
case txStateSet :
596
599
if glog .V (5 ) {
597
600
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 {
653
656
654
657
// Transaction case.
655
658
656
- glog .Info ("doWrite: op: " , op , " " , key , " : " , value )
659
+ glog .Info ("doWrite: op: " , op , " " , d . key2redis ( ts , key ) , " : " , value )
657
660
658
661
switch op {
659
662
case txOpHMSet , txOpHDel :
@@ -1099,7 +1102,6 @@ func (d *DB) StartTx(w []WatchKeys, tss []*TableSpec) error {
1099
1102
}
1100
1103
1101
1104
var e error = nil
1102
- var args []interface {}
1103
1105
var ret cvl.CVLRetCode
1104
1106
1105
1107
//Start CVL session
@@ -1115,6 +1117,44 @@ func (d *DB) StartTx(w []WatchKeys, tss []*TableSpec) error {
1115
1117
goto StartTxExit
1116
1118
}
1117
1119
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
+
1118
1158
// For each watchkey
1119
1159
// If a pattern, Get the keys, appending results to Cmd args.
1120
1160
// Else append keys to the Cmd args
@@ -1133,7 +1173,7 @@ func (d *DB) StartTx(w []WatchKeys, tss []*TableSpec) error {
1133
1173
1134
1174
redisKeys , e := d .client .Keys (redisKey ).Result ()
1135
1175
if e != nil {
1136
- glog .Warning ("StartTx : Keys: " + e .Error ())
1176
+ glog .Warning ("performWatch : Keys: " + e .Error ())
1137
1177
continue
1138
1178
}
1139
1179
for j := 0 ; j < len (redisKeys ); j ++ {
@@ -1148,27 +1188,22 @@ func (d *DB) StartTx(w []WatchKeys, tss []*TableSpec) error {
1148
1188
}
1149
1189
1150
1190
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
1153
1193
}
1154
1194
1155
1195
// Issue the WATCH
1156
1196
_ , e = d .client .Do (args ... ).Result ()
1157
1197
1158
1198
if e != nil {
1159
- glog .Warning ("StartTx : Do: WATCH " , args , " e: " , e .Error ())
1199
+ glog .Warning ("performWatch : Do: WATCH " , args , " e: " , e .Error ())
1160
1200
}
1161
1201
1162
- StartTxSkipWatch :
1202
+ SkipWatch :
1163
1203
1164
1204
// Switch State
1165
1205
d .txState = txStateWatch
1166
1206
1167
- StartTxExit:
1168
-
1169
- if glog .V (3 ) {
1170
- glog .Info ("StartTx: End: e: " , e )
1171
- }
1172
1207
return e
1173
1208
}
1174
1209
0 commit comments