ZOOM_set_error(c, ZOOM_ERROR_MEMCACHED, val);
return -1;
}
+ memcached_behavior_set(c->mc_st, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1);
#else
ZOOM_set_error(c, ZOOM_ERROR_MEMCACHED, "not enabled");
return -1;
wrbuf_destroy(w);
}
wrbuf_puts(r->mc_key, ";");
+ if (r->req_facets)
+ wrbuf_puts(r->mc_key, r->req_facets);
#endif
}
void ZOOM_memcached_search(ZOOM_connection c, ZOOM_resultset resultset)
{
#if HAVE_LIBMEMCACHED_MEMCACHED_H
- /* TODO: add sorting */
if (c->mc_st && resultset->live_set == 0)
{
size_t v_len;
char *v = memcached_get(c->mc_st, wrbuf_buf(resultset->mc_key),
wrbuf_len(resultset->mc_key),
&v_len, &flags, &rc);
+ /* count;precision (ASCII) + '\0' + BER buffer for otherInformation */
if (v)
{
ZOOM_Event event;
- WRBUF w = wrbuf_alloc();
+ size_t lead_len = strlen(v) + 1;
- wrbuf_write(w, v, v_len);
- free(v);
- resultset->size = odr_atoi(wrbuf_cstr(w));
-
- yaz_log(YLOG_LOG, "For key %s got value %s",
- wrbuf_cstr(resultset->mc_key), wrbuf_cstr(w));
+ resultset->size = odr_atoi(v);
- wrbuf_destroy(w);
+ yaz_log(YLOG_LOG, "For key %s got value %s lead_len=%d len=%d",
+ wrbuf_cstr(resultset->mc_key), v, (int) lead_len,
+ (int) v_len);
+ if (v_len > lead_len)
+ {
+ Z_OtherInformation *oi = 0;
+ int oi_len = v_len - lead_len;
+ odr_setbuf(resultset->odr, v + lead_len, oi_len, 0);
+ if (!z_OtherInformation(resultset->odr, &oi, 0, 0))
+ {
+ yaz_log(YLOG_WARN, "oi decoding failed");
+ free(v);
+ return;
+ }
+ ZOOM_handle_search_result(c, resultset, oi);
+ ZOOM_handle_facet_result(c, resultset, oi);
+ }
+ free(v);
event = ZOOM_Event_create(ZOOM_EVENT_RECV_SEARCH);
ZOOM_connection_put_event(c, event);
resultset->live_set = 1;
#endif
}
-void ZOOM_memcached_hitcount(ZOOM_connection c, ZOOM_resultset resultset)
+void ZOOM_memcached_hitcount(ZOOM_connection c, ZOOM_resultset resultset,
+ Z_OtherInformation *oi, const char *precision)
{
#if HAVE_LIBMEMCACHED_MEMCACHED_H
if (c->mc_st && resultset->live_set == 0)
uint32_t flags = 0;
memcached_return_t rc;
time_t expiration = 36000;
- char str[40];
+ char *str;
+ ODR odr = odr_createmem(ODR_ENCODE);
+ char *oi_buf = 0;
+ int oi_len = 0;
+ char *key;
+
+ str = odr_malloc(odr, 20 + strlen(precision));
+ /* count;precision (ASCII) + '\0' + BER buffer for otherInformation */
+ sprintf(str, ODR_INT_PRINTF ";%s", resultset->size, precision);
+ if (oi)
+ {
+ z_OtherInformation(odr, &oi, 0, 0);
+ oi_buf = odr_getbuf(odr, &oi_len, 0);
+ }
+ key = odr_malloc(odr, strlen(str) + 1 + oi_len);
+ strcpy(key, str);
+ if (oi_len)
+ memcpy(key + strlen(str) + 1, oi_buf, oi_len);
- sprintf(str, ODR_INT_PRINTF, resultset->size);
rc = memcached_set(c->mc_st,
- wrbuf_buf(resultset->mc_key),wrbuf_len(resultset->mc_key),
- str, strlen(str), expiration, flags);
- yaz_log(YLOG_LOG, "Store hit count key=%s value=%s rc=%u %s",
- wrbuf_cstr(resultset->mc_key), str, (unsigned) rc,
+ wrbuf_buf(resultset->mc_key),
+ wrbuf_len(resultset->mc_key),
+ key, strlen(str) + 1 + oi_len, expiration, flags);
+ yaz_log(YLOG_LOG, "Store hit count key=%s value=%s oi_len=%d rc=%u %s",
+ wrbuf_cstr(resultset->mc_key), str, oi_len, (unsigned) rc,
memcached_last_error_message(c->mc_st));
+ odr_destroy(odr);
}
#endif
}
!diag && npr->which == Z_NamePlusRecord_databaseRecord)
{
WRBUF k = wrbuf_alloc();
+ WRBUF rec_sha1 = wrbuf_alloc();
uint32_t flags = 0;
memcached_return_t rc;
time_t expiration = 36000;
syntax ? syntax : "",
elementSetName ? elementSetName : "",
schema ? schema : "");
+
+ wrbuf_sha1_write(rec_sha1, rec_buf, rec_len, 1);
+
rc = memcached_set(r->connection->mc_st,
- wrbuf_buf(k),wrbuf_len(k),
+ wrbuf_buf(k), wrbuf_len(k),
+ wrbuf_buf(rec_sha1), wrbuf_len(rec_sha1),
+ expiration, flags);
+
+ yaz_log(YLOG_LOG, "Store record key=%s val=%s rc=%u %s",
+ wrbuf_cstr(k), wrbuf_cstr(rec_sha1), (unsigned) rc,
+ memcached_last_error_message(r->connection->mc_st));
+
+ rc = memcached_add(r->connection->mc_st,
+ wrbuf_buf(rec_sha1), wrbuf_len(rec_sha1),
rec_buf, rec_len,
expiration, flags);
- yaz_log(YLOG_LOG, "Store record lkey=%s len=%d rc=%u %s",
- wrbuf_cstr(k), rec_len, (unsigned) rc,
+ yaz_log(YLOG_LOG, "Add record key=%s rec_len=%d rc=%u %s",
+ wrbuf_cstr(rec_sha1), rec_len, (unsigned) rc,
memcached_last_error_message(r->connection->mc_st));
+
odr_destroy(odr);
wrbuf_destroy(k);
+ wrbuf_destroy(rec_sha1);
}
#endif
}
if (r->connection && r->connection->mc_st)
{
WRBUF k = wrbuf_alloc();
- size_t v_len;
- char *v_buf;
+ char *sha1_buf;
+ size_t sha1_len;
uint32_t flags;
memcached_return_t rc;
schema ? schema : "");
yaz_log(YLOG_LOG, "Lookup record %s", wrbuf_cstr(k));
- v_buf = memcached_get(r->connection->mc_st, wrbuf_buf(k), wrbuf_len(k),
- &v_len, &flags, &rc);
+ sha1_buf = memcached_get(r->connection->mc_st,
+ wrbuf_buf(k), wrbuf_len(k),
+ &sha1_len, &flags, &rc);
+
wrbuf_destroy(k);
- if (v_buf)
+ if (sha1_buf)
{
- Z_NamePlusRecord *npr = 0;
-
- odr_setbuf(r->odr, v_buf, v_len, 0);
- z_NamePlusRecord(r->odr, &npr, 0, 0);
- free(v_buf);
- if (npr)
- yaz_log(YLOG_LOG, "returned memcached copy");
- return npr;
+ size_t v_len;
+ char *v_buf;
+
+ yaz_log(YLOG_LOG, "Lookup record %.*s", (int) sha1_len, sha1_buf);
+ v_buf = memcached_get(r->connection->mc_st, sha1_buf, sha1_len,
+ &v_len, &flags, &rc);
+ free(sha1_buf);
+ if (v_buf)
+ {
+ Z_NamePlusRecord *npr = 0;
+
+ odr_setbuf(r->odr, v_buf, v_len, 0);
+ z_NamePlusRecord(r->odr, &npr, 0, 0);
+ free(v_buf);
+ if (npr)
+ yaz_log(YLOG_LOG, "returned memcached copy");
+ return npr;
+ }
}
}
#endif