Skip to content

Commit

Permalink
MB-7542: Set seq_id to 1 if not set or as zero
Browse files Browse the repository at this point in the history
For offline upgrade or data restore, set seq_id to 1 when it is not set
or set as zero.

Change-Id: I5ff72068dfb07026e6cc528bf467055bcfe8b00f
Reviewed-on: http://review.couchbase.org/24003
Reviewed-by: Steve Yen <steve.yen@gmail.com>
Tested-by: Bin Cui <bin.cui@gmail.com>
Reviewed-on: http://review.couchbase.org/24034
  • Loading branch information
bcui6611 authored and Farshid Ghods committed Jan 17, 2013
1 parent b9ba5c1 commit afc26d0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
10 changes: 7 additions & 3 deletions pump_mc.py
Expand Up @@ -332,10 +332,14 @@ def cmd_request(self, cmd, vbucket_id, key, val, flg, exp, cas, meta, opaque):
if len(seq_no) < 8:
# The seq_no might be 32-bits from 2.0DP4, so pad with 0x00's.
seq_no = ('\x00\x00\x00\x00\x00\x00\x00\x00' + seq_no)[-8:]
ext = (struct.pack(">II", flg, exp) + seq_no +
struct.pack(">Q", cas))
check_seqno, = struct.unpack(">Q", seq_no)
if check_seqno:
ext = (struct.pack(">II", flg, exp) + seq_no +
struct.pack(">Q", cas))
else:
ext = struct.pack(">IIQQ", flg, exp, 1, cas)
else:
ext = struct.pack(">IIQQ", flg, exp, 0, cas)
ext = struct.pack(">IIQQ", flg, exp, 1, cas)
elif (cmd == memcacheConstants.CMD_SET or
cmd == memcacheConstants.CMD_ADD):
ext = struct.pack(memcacheConstants.SET_PKT_FMT, flg, exp)
Expand Down
31 changes: 19 additions & 12 deletions pump_sfd.py
Expand Up @@ -280,7 +280,13 @@ def run(self):
d = couchstore.DocumentInfo(str(key))
d.revMeta = str(struct.pack(SFD_REV_META, cas, exp, flg))
if meta:
d.revSequence = struct.unpack(SFD_REV_SEQ, meta)
if len(meta) > 8:
meta = meta[0:8]
if len(meta) < 8:
meta = ('\x00\x00\x00\x00\x00\x00\x00\x00' + meta)[-8:]
d.revSequence, = struct.unpack(SFD_REV_SEQ, meta)
else:
d.revSequence = 1

if cmd == memcacheConstants.CMD_TAP_MUTATION:
v = str(val)
Expand Down Expand Up @@ -404,20 +410,21 @@ def consume_design(opts, sink_spec, sink_map,
bulk_keys = []
bulk_vals = []

for row in sd['rows']:
logging.debug("design_doc row: " + str(row))
if sd:
for row in sd['rows']:
logging.debug("design_doc row: " + str(row))

d = couchstore.DocumentInfo(str(row['id']))
if '_rev' in row['doc']:
d.revMeta = str(row['doc']['_rev'])
del row['doc']['_rev']
d.contentType = couchstore.DocumentInfo.IS_JSON
d = couchstore.DocumentInfo(str(row['id']))
if '_rev' in row['doc']:
d.revMeta = str(row['doc']['_rev'])
del row['doc']['_rev']
d.contentType = couchstore.DocumentInfo.IS_JSON

bulk_keys.append(d)
bulk_vals.append(json.dumps(row['doc']))
bulk_keys.append(d)
bulk_vals.append(json.dumps(row['doc']))

if bulk_keys and bulk_vals:
store.saveMultiple(bulk_keys, bulk_vals) # TODO: Compress ddocs?
if bulk_keys and bulk_vals:
store.saveMultiple(bulk_keys, bulk_vals) # TODO: Compress ddocs?

store.commit()
store.close()
Expand Down

0 comments on commit afc26d0

Please sign in to comment.