static int seq_action_compare(const void *actv1, const void *actv2) { const couchfile_modify_action *act1, *act2; act1 = (const couchfile_modify_action *) actv1; act2 = (const couchfile_modify_action *) actv2; uint64_t seq1, seq2; seq1 = decode_sequence_key(act1->key); seq2 = decode_sequence_key(act2->key); if (seq1 < seq2) { return -1; } if (seq1 == seq2) { if (act1->type < act2->type) { return -1; } if (act1->type > act2->type) { return 1; } return 0; } if (seq1 > seq2) { return 1; } return 0; }
int seq_cmp(const sized_buf *k1, const sized_buf *k2) { uint64_t e1val = decode_sequence_key(k1); uint64_t e2val = decode_sequence_key(k2); if (e1val == e2val) { return 0; } return (e1val < e2val ? -1 : 1); }
static couchstore_error_t by_seq_read_docinfo(DocInfo **pInfo, sized_buf *k, sized_buf *v) { const raw_seq_index_value *raw = (const raw_seq_index_value*)v->buf; ssize_t extraSize = v->size - sizeof(*raw); if (extraSize < 0) { return COUCHSTORE_ERROR_CORRUPT; } uint32_t idsize, datasize; decode_kv_length(&raw->sizes, &idsize, &datasize); uint64_t bp = decode_raw48(raw->bp); int deleted = (bp & BP_DELETED_FLAG) != 0; bp &= ~BP_DELETED_FLAG; uint8_t content_meta = decode_raw08(raw->content_meta); uint64_t rev_seq = decode_raw48(raw->rev_seq); uint64_t db_seq = decode_sequence_key(k); sized_buf id = {v->buf + sizeof(*raw), idsize}; sized_buf rev_meta = {id.buf + idsize, extraSize - id.size}; DocInfo* docInfo = couchstore_alloc_docinfo(&id, &rev_meta); if (!docInfo) { return COUCHSTORE_ERROR_ALLOC_FAIL; } docInfo->db_seq = db_seq; docInfo->rev_seq = rev_seq; docInfo->deleted = deleted; docInfo->bp = bp; docInfo->size = datasize; docInfo->content_meta = content_meta; *pInfo = docInfo; return COUCHSTORE_SUCCESS; }
static int by_seq_read_docinfo(DocInfo **pInfo, sized_buf *k, sized_buf *v) { const raw_seq_index_value *raw = (const raw_seq_index_value*)v->buf; ssize_t extraSize = v->size - sizeof(*raw); if (extraSize < 0) { return COUCHSTORE_ERROR_CORRUPT; } uint32_t idsize, datasize; decode_kv_length(&raw->sizes, &idsize, &datasize); uint64_t bp = decode_raw48(raw->bp); int deleted = (bp & BP_DELETED_FLAG) != 0; bp &= ~BP_DELETED_FLAG; uint8_t content_meta = decode_raw08(raw->content_meta); uint64_t rev_seq = decode_raw48(raw->rev_seq); uint64_t db_seq = decode_sequence_key(k); DocInfo* docInfo = malloc(sizeof(DocInfo) + extraSize); if (!docInfo) { return COUCHSTORE_ERROR_ALLOC_FAIL; } char *rbuf = (char *) docInfo; memcpy(rbuf + sizeof(DocInfo), v->buf + sizeof(*raw), extraSize); *pInfo = docInfo; docInfo->db_seq = db_seq; docInfo->rev_seq = rev_seq; docInfo->deleted = deleted; docInfo->bp = bp; docInfo->size = datasize; docInfo->content_meta = content_meta; docInfo->id.buf = rbuf + sizeof(DocInfo); docInfo->id.size = idsize; docInfo->rev_meta.buf = rbuf + sizeof(DocInfo) + idsize; docInfo->rev_meta.size = extraSize - idsize; return 0; }