2007-11-29 14:18:54 +00:00
|
|
|
/* -*- mode: C; c-basic-offset: 4 -*- */
|
2008-01-24 15:10:32 +00:00
|
|
|
#ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved."
|
2007-11-29 14:18:54 +00:00
|
|
|
|
2007-11-14 17:58:38 +00:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include "brt-internal.h"
|
2008-02-08 03:17:38 +00:00
|
|
|
#include "toku_assert.h"
|
2007-11-14 17:58:38 +00:00
|
|
|
|
|
|
|
// Calculate the fingerprint for a kvpair
|
|
|
|
static inline u_int32_t toku_calc_more_crc32_kvpair (u_int32_t crc, const void *key, int keylen, const void *val, int vallen) {
|
|
|
|
int i;
|
|
|
|
i = htonl(keylen);
|
|
|
|
crc = toku_crc32(crc, (void*)&i, 4);
|
|
|
|
crc = toku_crc32(crc, key, keylen);
|
|
|
|
i = htonl(vallen);
|
|
|
|
crc = toku_crc32(crc, (void*)&i, 4);
|
|
|
|
crc = toku_crc32(crc, val, vallen);
|
|
|
|
return crc;
|
|
|
|
}
|
|
|
|
|
2008-04-07 01:30:25 +00:00
|
|
|
#if 0
|
|
|
|
u_int32_t toku_calccrc32_kvpair (const void *key, int keylen, const void *val, int vallen) {
|
2007-11-14 17:58:38 +00:00
|
|
|
return toku_calc_more_crc32_kvpair(toku_null_crc, key, keylen, val, vallen);
|
|
|
|
}
|
|
|
|
|
2008-04-02 23:40:36 +00:00
|
|
|
u_int32_t toku_calccrc32_kvpair_struct (const struct kv_pair *kvp) {
|
|
|
|
return toku_calccrc32_kvpair(kv_pair_key_const(kvp), kv_pair_keylen(kvp),
|
|
|
|
kv_pair_val_const(kvp), kv_pair_vallen(kvp));
|
|
|
|
}
|
2008-04-07 01:30:25 +00:00
|
|
|
#endif
|
2008-04-02 23:40:36 +00:00
|
|
|
|
2008-04-04 18:22:01 +00:00
|
|
|
u_int32_t toku_calccrc32_cmd (u_int32_t type, TXNID xid, const void *key, u_int32_t keylen, const void *val, u_int32_t vallen) {
|
2007-11-14 17:58:38 +00:00
|
|
|
unsigned char type_c = type;
|
2008-02-05 18:25:23 +00:00
|
|
|
unsigned int a = htonl(xid>>32);
|
|
|
|
unsigned int b = htonl(xid&0xffffffff);
|
|
|
|
return toku_calc_more_crc32_kvpair(toku_crc32(toku_crc32(toku_crc32(toku_null_crc,
|
|
|
|
&type_c, 1),
|
|
|
|
&a, 4),
|
|
|
|
&b, 4),
|
2007-11-14 17:58:38 +00:00
|
|
|
key, keylen, val, vallen);
|
|
|
|
}
|
|
|
|
|
2008-02-04 15:04:22 +00:00
|
|
|
u_int32_t toku_calccrc32_cmdstruct (BRT_CMD cmd) {
|
2008-04-07 01:30:25 +00:00
|
|
|
switch (cmd->type) {
|
|
|
|
case BRT_INSERT:
|
|
|
|
case BRT_DELETE_ANY:
|
|
|
|
case BRT_DELETE_BOTH:
|
|
|
|
case BRT_COMMIT_ANY:
|
|
|
|
case BRT_COMMIT_BOTH:
|
|
|
|
case BRT_ABORT_ANY:
|
|
|
|
case BRT_ABORT_BOTH:
|
2008-02-05 18:25:23 +00:00
|
|
|
return toku_calccrc32_cmd (cmd->type, cmd->xid, cmd->u.id.key->data, cmd->u.id.key->size, cmd->u.id.val->data, cmd->u.id.val->size);
|
2008-04-07 01:30:25 +00:00
|
|
|
case BRT_NONE:
|
2008-02-08 03:17:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2008-04-07 01:30:25 +00:00
|
|
|
assert(0); /* Should not have come here. */
|
|
|
|
return 0;
|
2007-11-14 17:58:38 +00:00
|
|
|
}
|