kumofs ã®ã¹ãã¬ã¼ã¸ã®APIã«ã¤ãã¦èª¿ã¹ã¦ã¿ã¾ããã
å ã kumofs 㯠configure æã«ã¹ãã¬ã¼ã¸ãé¸æã§ããããã«ãªã£ã¦ãã¦ãæ¬ä½é¨åã¨ã¹ãã¬ã¼ã¸é¨åã API ã«ããããç¨åº¦åé¢ããã¦ãã¾ãããªã®ã§ç¬èªã«ã¹ãã¬ã¼ã¸ãä½æãããã¨ããããªã«é£ãããªãã§ããã¨æãã¾ãã
ã¹ãã¬ã¼ã¸é¨ã«ã¯21åã®é¢æ°ãå¿ è¦ã§ããé¢æ°ã¯ src/storage/interface.h ã§å®ç¾©ããã¦ãã¾ãã
以ä¸ãåé¢æ°ã«ã¤ãã¦èª¬æãã¾ããé¢æ°åã®ãxxxxxãã¯é常ã¹ãã¬ã¼ã¸åºæã®ååãæå®ãã¾ãããã¨ãã° kumofs æ¨æºã®ã¹ãã¬ã¼ã¸ã§ãã Tokyo Cabinet ã® Hash ã®å ´å㯠tchdb ã¨ãªã£ã¦ãã¾ãã
åæ¸ãã¦ãããããããªãã®ã§ããã¾ãä¿¡ããªãæ¹ãããã¨æãã¾ãã
ã¹ãã¬ã¼ã¸å±¤ã«æ¸¡ããããã¼ã¨ãã¼ã¿ã¯ã¯ã©ã¤ã¢ã³ãããæå®ããããã®ãã®ã¾ã¾ã§ã¯ãªããkumofs 管çç¨ã®ããããã¤ãã¦ãã¾ãããã¼ã®ããã㯠8ãã¤ãããã¼ã¿ã®ããã㯠10ãã¤ãã§ãã詳ãã㯠doc/doc.ja.md ã® FAQ ãã¼ã¿ãã¼ã¹ãã¡ã¤ã«ã®ãã©ã¼ããããè¦ã¦ãã ããã
create
static void* kumo_xxxxx_create(void)
åæåãkumo-server èµ·åæã«å¼ã°ãã¾ãã
æ»ãå¤ã¯ä»»æã®ãã¤ã³ã¿ã§ãããã以å¤ã®é¢æ°ã®å¼ã³åºãæã« data ã¨ãã¦æ¸¡ããããã®ã§ãã
NULL ãè¿ãã¨åæåã«å¤±æãããã¨ã表ããkumo-server ã¯çµäºãã¾ãã
free
static void kumo_xxxxx_free(void* data)
kumo-server çµäºæã«å¼ã°ãã¾ãã
open
static bool kumo_xxxxx_open(void* data, const char* path)
kumo-server ã attach ãããæã«å¼ã°ãã¾ãã
path 㯠kumo-server ã® -s ãªãã·ã§ã³ã§æå®ããããã¡ã¤ã«åã§ãã
close
static void kumo_xxxxx_close(void* data)
kumo-server çµäºæã«å¼ã°ãã¾ãã
get
static const char* kumo_xxxxx_get(void* data, const char* key, uint32_t keylen, uint32_t* result_vallen, msgpack_zone* zone)
ãã¼ã¿ãåãåºãã¾ãã
key, keylen ã¯ãã¼ã®å¤ã¨é·ãã示ãã¾ãã
æ»ãå¤ã§åãåºãããã¼ã¿ã®å¤ã®ãã¤ã³ã¿ãè¿ãã¾ãããã¼ã¿ãè¦ã¤ãããªãã£ãå ´åãå¦çã«å¤±æããå ´å㯠NULL ãè¿ãã¾ãã
result_vallen ã¯ãã¼ã¿ã®é·ããè¿ããã¤ã³ã¿ã§ãã
ãã¼ã¿ãä¸è¦ã«ãªã£ãå ´åã®å¦çã¯æ¬¡ã®ããã«ç»é²ãã¾ãã
msgpack_zone_push_finalizer(zone, é¢æ°å, é¢æ°ã«æ¸¡ãå¼æ°);
msgpack_zone_push_finalizer() ã 0 ãè¿ããå ´åã¯ç»é²ã«å¤±æãã¦ããã®ã§ãkumo_xxxxx_get() ã NULL ãè¿ãå¿ è¦ãããã¾ãã
ãã¼ã¿ãæ ¼ç´ããã¡ã¢ãªã malloc() ã§ç²å¾ãããã¤ã³ã¿ val ã§ä¿æãã¦ããå ´åã®å¦çã¯ãé常次ã®ããã«ãªãã¾ãã
if (!msgpack_zone_push_finalizer(zone, free, val)) { free(val); return NULL; }
get_header
static int32_t kumo_xxxxx_get_header(void* data, const char* key, uint32_t keylen, char* result_val, uint32_t vallen)
kumo_xxxxx_get() ã¨åããå¤ãåãåºãã¾ãããè¿ããã¼ã¿ã®æ大é·ãæå®ããã¦ãã¾ãã
key, keylen ã¯ãã¼ã®å¤ã¨é·ãã示ãã¾ãã
åãåºããå¤ã¯ result_val ã«å
¥ãã¾ããresult_val ã®å¤§ãã㯠vallen ã§æå®ããã¦ãã¾ãã
æ»ãå¤ã¯ result_val ã«æ¸ãè¾¼ãã ãã¼ã¿ã®é·ãã§ãããã¼ã¿ãè¦ã¤ãããªãã£ãå ´å㯠-1 ãè¿ãã¾ãã
set
static bool kumo_xxxxx_set(void* data, const char* key, uint32_t keylen, const char* val, uint32_t vallen)
ãã¼ã¨ãã¼ã¿ãæ ¼ç´ãã¾ãã
key, keylen ã¯ãã¼ã®å¤ã¨é·ãã示ãã¾ãã
val, vallen ã¯ãã¼ã¿ã®å¤ã¨é·ãã示ãã¾ãã
æåããå ´å true, 失æããå ´å false ãè¿ãã¾ãã
del
static bool kumo_xxxxx_del(void* data, const char* key, uint32_t keylen, kumo_storage_casproc proc, void* casdata)
ãã¼ã¨ãã¼ã¿ãåé¤ãã¾ãã
key, keylen ã¯ãã¼ã®å¤ã¨é·ãã示ãã¾ãã
proc 㨠casdata ã¯CAS処理ã®ããã«ä½¿ç¨ããã¾ãã
æå®ããããã¼ãåå¨ããå ´åããproc(casdata, æ¢åãã¼ã¿å¤, æ¢åãã¼ã¿é·)ããå¼ã³åºãã¾ãã
proc ã true ãè¿ããå ´åãã¼ã¿ãåé¤ã㦠true ãè¿ãã¾ãã
proc ã false ãè¿ããå ´åã¯ãã¼ã¿ãåé¤ããã« false ãè¿ãã¾ãã
update
static bool kumo_xxxxx_update(void* data, const char* key, uint32_t keylen, const char* val, uint32_t vallen, kumo_storage_casproc proc, void* casdata)
ãã¼ã«å¯¾å¿ãããã¼ã¿ãæ´æ°ãã¾ãã
key, keylen ã¯ãã¼ã®å¤ã¨é·ãã示ãã¾ãã
val, vallen ã¯ãã¼ã¿ã®å¤ã¨é·ãã示ãã¾ãã
proc 㨠casdata ã¯CAS処理ã®ããã«ä½¿ç¨ããã¾ãã
æå®ããããã¼ãåå¨ããªãå ´åãã¼ã¿ãç»é²ãã¾ãã
æå®ããããã¼ãåå¨ããå ´åããproc(casdata, æ¢åãã¼ã¿å¤, æ¢åãã¼ã¿é·)ããå¼ã³åºãã¾ãã
proc ã true ãè¿ããå ´åãã¼ã¿ãæ´æ°ã㦠true ãè¿ãã¾ãã
proc ã false ãè¿ããå ´åã¯ãã¼ã¿ãæ´æ°ããã« false ãè¿ãã¾ãã
rnum
static uint64_t kumo_xxxxx_rnum(void* data)
ã¹ãã¬ã¼ã¸å ã®å ¨ãã¼ã¿ã®æ°ãè¿ãã¾ãã
backup
static bool kumo_xxxxx_backup(void* data, const char* dstpath)
kumoctl backup æã«å¼ã°ãã¾ãã
dstpath ã¯ããã¯ã¢ããå
ã®ãã¡ã¤ã«åã§ãã
æåããå ´å㯠true, 失æããå ´å㯠false ãè¿ãã¾ãã
error
static const char* kumo_xxxxx_error(void* data)
ã¨ã©ã¼ã¡ãã»ã¼ã¸ãè¿ãã¾ãã
for_each
static int kumo_xxxxx_for_each(void* data, void* user, int (*func)(void* user, void* iterator_data))
ã¹ãã¬ã¼ã¸ã®å
¨ãã¼ã¿ãé çªã«æå®ãããé¢æ° func ã«æ¸¡ãã¾ãã
func ã®ç¬¬ä¸å¼æ°ã¯ user ããã®ã¾ã¾æ¸¡ãã¾ãã
func ã®ç¬¬äºå¼æ°ã¯1件ã®ãã¼ã¿ã表ããã¤ã³ã¿ã§ kumo_xxxxx_iterator_ ã§å§ã¾ãé¢æ°ã«æ¸¡ããã¾ãã
iterator_key
static const char* kumo_xxxxx_iterator_key(void* iterator_data)
iterator_data ãããã¼å¤ã®ãã¤ã³ã¿ãåãåºãã¾ãã
iterator_val
static const char* kumo_xxxxx_iterator_val(void* iterator_data)
iterator_data ãããã¼ã¿å¤ã®ãã¤ã³ã¿ãåãåºãã¾ãã
iterator_keylen
static size_t kumo_xxxxx_iterator_keylen(void* iterator_data)
iterator_data ãããã¼ã®é·ããåãåºãã¾ãã
iterator_vallen
static size_t kumo_xxxxx_iterator_vallen(void* iterator_data)
iterator_data ãããã¼ã¿ã®é·ããåãåºãã¾ãã
iterator_release_key
static const char* kumo_xxxxx_iterator_release_key(void* iterator_data, msgpack_zone* zone)
iterator_data ãããã¼å¤ã®ãã¤ã³ã¿ãåãåºãã¾ãã
ã¡ã¢ãªç®¡çãã¤ãã¬ã¼ã¿ãã zone ã«ç§»ãã¾ãããã¼å¤ã®ã¡ã¢ãªè§£æ¾ã¯ msgpack_zone_push_finalizer() 㧠zone ã«ã¾ããã¾ããã¤ãã¬ã¼ã¿å´ã§ã¡ã¢ãªã解æ¾ãã¦ã¯ããã¾ããã
å®éã«ã¯ãã®é¢æ°ã¯ kumofs ã§ã¯ä½¿ç¨ããã¦ããªãããã«è¦ãã¾ãã
iterator_release_val
static const char* kumo_xxxxx_iterator_release_val(void* iterator_data, msgpack_zone* zone)
iterator_data ãããã¼ã¿å¤ã®ãã¤ã³ã¿ãåãåºãã¾ãã
ã¡ã¢ãªç®¡çãã¤ãã¬ã¼ã¿ãã zone ã«ç§»ãã¾ãããã¼ã¿å¤ã®ã¡ã¢ãªè§£æ¾ã¯ msgpack_zone_push_finalizer() 㧠zone ã«ã¾ããã¾ããã¤ãã¬ã¼ã¿å´ã§ã¡ã¢ãªã解æ¾ãã¦ã¯ããã¾ããã
å®éã«ã¯ãã®é¢æ°ã¯ kumofs ã§ã¯ä½¿ç¨ããã¦ããªãããã«è¦ãã¾ãã
iterator_del
static bool kumo_xxxxx_iterator_del(void* iterator_data, kumo_storage_casproc proc, void* casdata)
iterator_data ã示ããã¼ã¿ãåé¤ãã¾ãã
æåããå ´å㯠true, 失æããå ´å㯠false ãè¿ãã¾ãã
proc, casdata 㯠kumo_xxxxx_del() ã¨åæ§ã§ãã
iterator_del_force
static bool kumo_xxxxx_iterator_del_force(void* iterator_data)
iterator_data ã示ããã¼ã¿ãåé¤ãã¾ãã
kumo_storage_init
ä¸è¨åé¢æ°ã®ãã¤ã³ã¿ãå
¥ã£ã¦ã kumofs_storage_op æ§é ä½ã®ãã¤ã³ã¿ãè¿ãã¾ããkumo-server èµ·åæã«å¼ã°ãã¾ãã以éã®ã¹ãã¬ã¼ã¸å¦çã¯ãã®æ§é ä½ã®ã¡ã³ãé¢æ°ãéãã¦å¦çããã¾ãã
次ã®ããã«ä½¿ç¨ãã¾ãã
static kumo_storage_op kumo_xxxxx_op = { kumo_xxxxx_create, kumo_xxxxx_free, kumo_xxxxx_open, kumo_xxxxx_close, kumo_xxxxx_get, kumo_xxxxx_get_header, kumo_xxxxx_set, kumo_xxxxx_del, kumo_xxxxx_update, NULL, kumo_xxxxx_rnum, kumo_xxxxx_backup, kumo_xxxxx_error, kumo_xxxxx_for_each, kumo_xxxxx_iterator_key, kumo_xxxxx_iterator_val, kumo_xxxxx_iterator_keylen, kumo_xxxxx_iterator_vallen, kumo_xxxxx_iterator_release_key, kumo_xxxxx_iterator_release_val, kumo_xxxxx_iterator_del, kumo_xxxxx_iterator_del_force, }; kumo_storage_op kumo_storage_init(void) { return kumo_xxxxx_op; }