int monary_load_timestamp_value(const bson_iter_t* bsonit, monary_column_item* citem, int idx) { uint32_t timestamp; uint32_t increment; char* dest; // Would be void*, but Windows compilers complain dest = (char*) citem->storage + idx*sizeof(int64_t); if (BSON_ITER_HOLDS_TIMESTAMP(bsonit)) { bson_iter_timestamp(bsonit, ×tamp, &increment); memcpy(dest, ×tamp, sizeof(int32_t)); memcpy(dest + sizeof(int32_t), &increment, sizeof(int32_t)); return 1; } else { return 0; } }
bool _mongoc_parse_cluster_time (const bson_t *cluster_time, uint32_t *timestamp, uint32_t *increment) { bson_iter_t iter; char *s; if (!cluster_time || !bson_iter_init_find (&iter, cluster_time, "clusterTime") || !BSON_ITER_HOLDS_TIMESTAMP (&iter)) { s = bson_as_json (cluster_time, NULL); MONGOC_ERROR ("Cannot parse cluster time from %s\n", s); bson_free (s); return false; } bson_iter_timestamp (&iter, timestamp, increment); return true; }
static void tail_collection (mongoc_collection_t *collection) { mongoc_cursor_t *cursor; uint32_t last_time; const bson_t *doc; bson_error_t error; bson_iter_t iter; BSON_ASSERT (collection); last_time = (uint32_t) time (NULL); while (true) { cursor = query_collection (collection, last_time); while (!mongoc_cursor_error (cursor, &error) && mongoc_cursor_more (cursor)) { if (mongoc_cursor_next (cursor, &doc)) { if (bson_iter_init_find (&iter, doc, "ts") && BSON_ITER_HOLDS_TIMESTAMP (&iter)) { bson_iter_timestamp (&iter, &last_time, NULL); } print_bson (doc); } } if (mongoc_cursor_error (cursor, &error)) { if (error.domain == MONGOC_ERROR_SERVER) { fprintf (stderr, "%s\n", error.message); exit (1); } } mongoc_cursor_destroy (cursor); sleep (1); } }