Tkrzw-RPCã®ã¬ããªã±ã¼ã·ã§ã³æ©è½ãå®ç¾ããããã«ãTkrzwæ¬ä½ã«æ´æ°ãã°æ©è½ãã¤ãããæ´æ°ãã°æ©è½ã¯ä»»æã®ã³ã¼ã«ããã¯ãå¼ã³åºãå®è£
ã«ãªã£ã¦ãã¦ãããã«ã¡ãã»ã¼ã¸ãã¥ã¼ãæ¥ç¶ããã¨ããã«ããªã¼ãã§ä»»æã®å¾å¦çãã§ããããã«ãªããä»åã¯ãã¡ãã»ã¼ã¸ãã¥ã¼ã®ã¬ã³ã¼ãã¨ãã¦ä¿åããæ´æ°ãã°ã使ã£ã¦ããã¼ã«ã«ç°å¢ã§ã¤ã³ã¯ãªã¡ã³ã¿ã«ããã¯ã¢ãããå®ç¾ããæ¹æ³ã«ã¤ãã¦èª¬æããã
ããããæ´æ°ãã°ã¨ã¯ä½ãã¨è¨ãã¨ããã¼ã¿ãã¼ã¹ã®åã ã®ã¬ã³ã¼ãã追å ãããå¤ãè¨å®ãããããSetæä½ã¨ãåã ã®ã¬ã³ã¼ããåé¤ããRemoveã¡ã½ããæä½ã¨ãå ¨ã¦ã®ã¬ã³ã¼ããåé¤ããClearã¡ã½ãããè¨é²ãããã®ã§ããããã¼ã¿ãã¼ã¹å é¨ã«ãã¬ã¼ãä»æãããã¨ã§ãåã ã®æ´æ°ãèµ·ããæã«ããã®äºæ ãè¨é²ãããã¨ãã§ããããããå¾ã§åçããã°ãå ã®ãã¼ã¿ãã¼ã¹ã復å ã§ããã¨ããããã ã
ãã¼ã¿ãã¼ã¹ã®å ¨ä½ã®ããã¯ã¢ãããã¡ã¤ã«ãå®æçã«ä½ãã°ãä¸ãä¸ãå ã®ãã¼ã¿ãã¼ã¹ãã¡ã¤ã«ãå£ããå ´åã«ããããã¯ã¢ãããã¡ã¤ã«ã使ã£ã¦å¾©æ§ããã°ãããã¯ã¢ããã®ä½ææç¹ã§ã®æ å ±ãåãæ»ããã¨ãã§ãããããããæå¾ã«ããã¯ã¢ãããä½æãã¦ããé害ãçºçããæç¹ã¾ã§ã®æ´æ°å 容ã¯å¤±ããã¦ãã¾ãããã®åé¡ã解決ããã®ããæ´æ°ãã°ã§ãããããã¯ã¢ãããã¡ã¤ã«ã¨æ´æ°ãã°ãçãæ®ã£ã¦ããã°ãããã¯ã¢ããä½ææç¹ä»¥éã®æ´æ°ãã°ãããã¯ã¢ãããã¡ã¤ã«ã«å¯¾ãã¦é©ç¨ãããã¨ã§ãé害çºçæç¹ã¾ã§ã®å®å ¨ãªæ å ±ã復å ã§ãããååã®ããã¯ã¢ããä½ææããã®å·®åãè¨é²ããã¨ããæå³ã§ã¯ãé£ç¶çã«ã¤ã³ã¯ãªã¡ã³ã¿ã«ããã¯ã¢ãããåãä»çµã¿ã ã¨ã¿ãªããã¨ãã§ããã
æ´æ°ãã°ã®ä»çµã¿ã端çã«èª¬æããããã«ãæ´æ°å 容ã端æ«ã«è¡¨ç¤ºãããã¬ã¼ãã¾ãã¯å®è£ ãã¦ãæ³¨å ¥ãã¦ã¿ãã
// DBM::UpdateLoggerãç¶æ¿ãã¦ãã¬ã¼ã¯ã©ã¹ãå®è£ ãã // WriteSetãWriteRemoveãWriteClearããªã¼ãã©ã¤ãããã class MyLogger : public DBM::UpdateLogger { Status WriteSet(std::string_view key, std::string_view value) override { std::cout << "SET:" << key << ":" << value << std::endl; return Status(Status::SUCCESS); } Status WriteRemove(std::string_view key) override { std::cout << "REMOVE:" << key << std::endl; return Status(Status::SUCCESS); } Status WriteClear() override { std::cout << "CLEAR" << std::endl; return Status(Status::SUCCESS); } }; // ãã¬ã¼ã¯ã©ã¹ã®ãªãã¸ã§ã¯ãããDBMã®ã¤ã³ã¹ã¿ã³ã¹ã«æ³¨å ¥ããã MyLogger ulog; dbm.SetUpdateLogger(&log); // æ®éã«ãã¼ã¿ãã¼ã¹ãæä½ããã¨ãå é¨çã«ãã¬ã¼ã®åé¢æ°ãå¼ã°ããã dbm.Set("japan", "tokyo"); dbm.Set("china", "beijing"); dbm.Remove("japan"); dbm.Clear();
ä¸è¨ã®ã³ã¼ããå®è¡ããã¨ã以ä¸ã®ãããªåºåãå¾ãããã
$ ./myloggersample SET:japan:tokyo SET:china:beijing REMOVE:japan CLEAR
æ´æ°ãã°ãå¿ç¨ãã¦ããããã¼ã¿ãã¼ã¹ã®æ´æ°ãå¥ã®ãã¼ã¿ãã¼ã¹ã«ãã®ã¾ã¾æµãã¦åæããããã¨ãã§ãããäºéåã¨ããæå³ã§ã¯ãããæãåç´ãªå®è£ ã ã
// ããã¯ã¢ããç¨ã®ãã¼ã¿ãã¼ã¹ãªãã¸ã§ã¯ããä½æããã HashDBM backup_dbm; backup_dbm.Open("casket-backup.tkh", true); // ããã¯ã¢ããç¨ãã¼ã¿ãã¼ã¹ãç»é²ãããã¬ã¼ãæ³¨å ¥ããã DBMUpdateLoggerDBM ulog(&backup_dbm); main_dbm.SetUpdateLogger(&ulog); // ã¡ã¤ã³ã®ãã¼ã¿ãã¼ã¹ãæ®éã«éç¨ããã main_dbm.Set("japan", "tokyo");
ãã ããæ´æ°ãã°ãå¥ã®ãã¼ã¿ãã¼ã¹ã§éç¨ããã®ã¯ããã¾ãå©ç¹ã¯ãªããã¡ã¤ã³ã®ãã¼ã¿ãã¼ã¹ãããã¯ã¢ããã®ãã¼ã¿ãã¼ã¹ã両æ¹ãªã³ã©ã¤ã³ã§ãªãã¨æ£å¸¸åä½ããªãã®ã ãããããã¯ã¢ãããã¼ã¿ãã¼ã¹ãæ¢ãã¦ãã¡ã¤ã«ã転éããã¨ãã£ããã¨ãã§ããªããã¾ããæ´æ°ã«ãããè² è·ã2åã«ãªã£ã¦ãã¾ãã
ãã®ä»£ããã«ãDBMUpdateLoggerMQã¨ãããã¬ã¼ã¯ã©ã¹ã使ã£ã¦ããã©ãããªæ§é ã®ãã¡ã¤ã«ã«ãã¼ã¿ã追è¨ãã¦ããã®ããããæ§æãåç´ãªã®ã§ããã°ãè¨é²ããããã®ãªã¼ãã¼ããããå°ãããããã«ããã¡ã¤ã«ãã¼ãã¼ã·ã§ã³ãå®è£ ãã¦ãã¦ããã¡ã¤ã«ãµã¤ãºãé¾å¤ãè¶ ããå ´åã«æ°ãããã¡ã¤ã«ãä½ã£ã¦ã以å¾ã®æ¸ãè¾¼ã¿ãããã«å¯¾ãã¦è¡ã£ã¦ããããã¾ããåã ã®æ´æ°ãã°ã«ã¯çºçæç¹ã®ã¿ã¤ã ã¹ã¿ã³ããã¤ãããããããã«ãã£ã¦ãä»»æã®ã¿ã¤ã ã¹ã¿ã³ã以å¾ã®ãã°ã®ã¿ãåãåºããã¨ãå¯è½ã¨ãªãã
DBMUpdateLoggerMQã¯ã©ã¹ã¯ã¡ãã»ã¼ã¸ãã¥ã¼ã®å®è£ ã§ããMesssageQueueã¯ã©ã¹ãå é¨çã«ç¨ãããååã®è¨äºã§è¿°ã¹ãããããã«ãã£ã¦ãã«ãã¹ã¬ããã§åå²ãã¡ã¤ã«ã®èªã¿æ¸ããã§ãããMesssageQueueã®ã³ã³ã¹ãã©ã¯ã¿ã«ãã¡ã¤ã«ã®æ¥é è¾ã¨æ大ãµã¤ãºãæå®ãã¦ã¤ã³ã¹ã¿ã³ã¹ãä½ãããããDBMUpdateLoggerMQã¯ã©ã¹ã®ã¤ã³ã¹ã¿ã³ã¹ã«æ³¨å ¥ãããããã«ãããDBMã«æ³¨å ¥ããã°ãæ´æ°ãã°ããã¡ã¤ã«ã«è¨é²ãããããã«ãªãã
ã¡ãã»ã¼ã¸ãã¥ã¼ãä½æããã MessageQueue mq; mq.Open("casket-ulog", 512<<20, MessageQueue::OPEN_TRUNCATE).OrDie(); // ãã¼ã¿ãã¼ã¹ãä½æãã TreeDBM dbm; dbm.Open("casket.tkt", true).OrDie(); // ãã¬ã¼ã®ä½æãã¦ãã¼ã¿ãã¼ã¹ã«æ³¨å ¥ããã DBMUpdateLoggerMQ ulog(&mq); dbm.SetUpdateLogger(&ulog); // æ®éã«ãã¼ã¿ãã¼ã¹ãéç¨ããã dbm.Set("two", "step");
ã·ã¹ãã ãã¯ã©ãã·ã¥ããããééã£ã¦rmã³ãã³ããæã¤ãªã©ãã¦ããªãããã¼ã¿ãã¼ã¹ãã¡ã¤ã«ãæ¶ããã¨ãããããã®å ´åãæå¾ã®ããã¯ã¢ãããã¡ã¤ã«ã«æ´æ°ãã°ãé©ç¨ãã復æ§ä½æ¥ãè¡ããããã¯ã¢ãããã¡ã¤ã«ã«ç´æ¥æ´æ°ãã°ãé©ç¨ããã®ã§ã¯ãªãã復æ§ç¨ã®ãã¡ã¤ã«ãã³ãã¼ãã¦ããä½æ¥ãè¡ãã®ãç¡é£ã ã
CopyFileData("casket-backup.tkt", "casket-restored.tkt").OrDie(); TreeDBM dbm; dbm.Open("casket-restored.tkt", true).OrDie(); DBMUpdateLoggerMQ::ApplyUpdateLogFromFiles(&dbm, "casket-ulog"); dbm.Close().OrDie();
ã¾ã¨ããã¨ãæ´æ°ãã°ãã¤ã³ã¯ãªã¡ã³ã¿ã«ããã¯ã¢ããã¨ãã¦æ±ãéç¨ã¯ä»¥ä¸ã®ããã«ãªããéç¨éå§æç¹ããæ´æ°ãã°ãåãç¶ãã¦ããå ´åããã«ããã¯ã¢ãããåãå¿ è¦ã¯ãªãã空ã®ãã¡ã¤ã«ã«æ´æ°ãã°ãé©ç¨ããã°ããããã ã
- ãã«ããã¯ã¢ãããåãã
- é常ã®éç¨ã§ãæ´æ°ãã°ãåããªãããæ´æ°æä½ãç¶ããã
- ã·ã¹ãã ãæ»ãã§ãä½ããã®çç±ã§ã¡ã¤ã³ã®ãã¼ã¿ãã¼ã¹ã失ãããã
- æå¾ã®ããã¯ã¢ããã«æ´æ°ãã°ãé©ç¨ããã
- æ´æ°ãã°ãã¢ã¼ã«ã¤ããããæ¶ããããã
幸ãã«ãã¦ã·ã¹ãã ãã¯ã©ãã·ã¥ããªãã£ãããæ´æ°ãã°ããã¤ã¾ã§ãå¢ãç¶ãã¦ãã¾ããããã ã¨å°ãã®ã§ãä¸å®ã®ééã§ããã¯ã¢ããã«æ´æ°ãã°ããã¼ã¸ãã¦ãå¤ããã®ãæ¨ã¦ããããã®ããã«ã¯ãç¾å¨ã®æ´æ°ãã°ãå ¨ã¦ããã¯ã¢ããã«é©ç¨ãã¦ãã¾ãã°ãããä¸è¿°ã®C++ã³ã¼ãã¨åçã®æä½ã¯ã³ãã³ãã©ã¤ã³ã§ãè¡ããã
$ cp casket-backup.tkt casket-restored.tkt $ tkrzw_dbm_util import --ulog 0 casket-restored.tkt casket-ulog
tkrzw_dbm importãµãã³ãã³ãã®-ulogãªãã·ã§ã³ã¯ãæä¾ããæå°ã¿ã¤ã ã¹ã¿ã³ããæå®ãããã¼ãã®å ´åãææã¡ã®å ¨ã¦ã®ãã°ãé©ç¨ãããã¨ã«ãªããç¾ç¶ã®æ´æ°ãã°ã®å ¨ã¦ãé©ç¨ããã¨ãããã¨ã¯ãææ°ã®ãæ¸ãè¾¼ã¿éä¸ãããããªããã¡ã¤ã«ãå¥ããã»ã¹ããèªãã¨ããããã£ããªãæä½ãè¡ããã¨ã«ãªããããããã¡ã¿ãã¼ã¿ãçªå µãé§ä½¿ãã¦ãä¸æ´åãèµ·ããªãããã«é æ ®ãã¦ããã
ããã¯ã¢ããã«å ¨ã¦ã®æ´æ°ãã°ãé©ç¨ãããªãã°ãææ°ä»¥å¤ã®æ´æ°ãã°ãã¡ã¤ã«ã¯rmã³ãã³ãã§æ¶ãã¦æ§ããªãã注ææ·±ã人ã¯ããã§æ°ä»ãã¨æãããæ¶ãããªãã£ãç¾å¨ã®ææ°ã®ãã¡ã¤ã«ã¯æ¬¡åã®åçã®æä½ã§ãã¾ãèªã¾ããã®ã§ãåãæ´æ°ãã°ãè¤æ°åé©ç¨ããããããã§ãã¿ããªå¤§å¥½ããªåªçæ§ï¼idempotenceï¼ã¨ããæ§è³ªãçãã¦ãããã¬ã³ã¼ãã®æä½ãSetã¨Removeã¨Clearã«éå®ããå ´åãåã ã®ã¬ã³ã¼ãã®æä½ã¯åªçã«ãªããããªãã¡ãåãæä½ã1åå®è¡ããã®ã¨ã2å以ä¸å®è¡ããã®ã§ã¯ãåãçµæãå¾ãããããã®åªçæ§ã¯ãæç³»åã§ä¸¦ã¹ãããè¤æ°ã®ã¬ã³ã¼ãæä½ã«é¢ãã¦ãæç«ããããã£ã¦ãåãæ´æ°ãã°ãã¡ã¤ã«ã2度以ä¸é©ç¨ãã¦ããåãçµæãå¾ãããã®ã ãåªçã§ããããã«ã¯ã該å½ã®æä½ã®çµæãèªèº«ã®ãã©ã¡ã¼ã¿ä»¥å¤ã®è¦å ã«å·¦å³ãããªããã¨ãå¿ è¦ã¨ãªãããæç³»åã§ä¸¦ã¹ãããSetã¨Removeã¨Clearã®ã·ã¼ã±ã³ã¹ã¯ãããæºããã¦ããã
æ´æ°ãã°ããç®çã®æ´æ°æä½ã®å®è¡åã«è¨é²ããã¹ãããå®è¡å¾ã«è¨é²ããã¹ããã¯ãè°è«ã®ä½å°ããããç¾ç¶ã§ã¯å®è¡åã«è¨é²ãã¦ããã®ã ããããããã¨ãæ´æ°ãã°ã«ã¯è¨é²ããã®ã«ãã¼ã¿ãã¼ã¹ã«æ´æ°ãåæ ããåã«ã·ã¹ãã ãæ»ã¬ãããããªãããã ããæ´æ°ãã°ãæå³ããªãæã«ã¯ããã¼ã¿ãã¼ã¹ã¯å¤±ããã¦ãã¦ãæ´æ°æä½ããã¼ã¿ãã¼ã¹ã«é©ç¨ããã¦ãããã©ããã¯ãã¯ã観測ä¸è½ãªã®ã§ãã©ãã§ããããåé¡ã¯ãæ´æ°æä½ã®æåãå¼ã³åºãå´ã«éç¥ããã¦ãããã©ããã ãæåãéç¥ããã¦ããªãã®ã«æåãã¦ããã®ãåé¡ã ããæåãã¦ããã®ã«æåãéç¥ããã¦ããªãã®ãåé¡ã ããããããã®åé¡ã¯ãæ´æ°ãã°ã®é©ç¨é åºã¨ã¯é¢ä¿ãªããæ´æ°ã«æåããã®ã«éç¥ã«å¤±æããã¨ããã®ã¯é常éç¨ã§ãèµ·ããããã®ã§ããã®å¯¾çã¯ã¢ããªã±ã¼ã·ã§ã³å´ã®ãã¸ãã¹ãã¸ãã¯ã«ä»»ããã
ã¨ããã§ãTkrzwã®ãã¼ã¿ãã¼ã¹ã¯å£ããªãããã«ã§ãã¦ãããHashDBMã¨TreeDBMã追è¨æ´æ°ã¢ã¼ãã§éç¨ããã°ããã¼ã¿ãã¼ã¹èªèº«ãæ´æ°ãã°ã¨ã¿ãªããã®ã§ãä»»æã®æç¹ã«ãã¼ã«ããã¯å¯è½ã§ãããSkipDBMã¯ä¸æãã¡ã¤ã«ã«ãããããå¦çã¨ã¢ãããã¯ãªrenameã§æ´æ°ããã®ã§ãããããä¸æ´åãèµ·ãããæ©ä¼ããªãããã£ã¦ãå°ãªãã¨ãHashDBM/TreeDBM/SkipDBMã«é¢ãã¦ããã·ã³åä½ã®ãã¼ã«ã«ã¬ãã«ã§ã®å ç¢æ§ãé«ããã¨ããç®çã§ã¯ãæ´æ°ãã°ã«å®ç¨çãªæå³ã¯ãªãããªã³ã¡ã¢ãªãã¼ã¿ãã¼ã¹ãæ´æ°ãã°ä»ãã§éç¨ããã¨ããã®ãé¢ç½ãã¨ã¯æãããæ´æ°ããåç §ãå§åçã«å¤ãã¨ããå ´å以å¤ã§ã¯ãæ®éã«ãã¡ã¤ã«ãã¼ã¿ãã¼ã¹ã使ã£ãæ¹ãå¹ççã ã
ããã«è¨ãã°ãã¡ã¤ã³ã®ãã¼ã¿ãã¼ã¹ãã¡ã¤ã«ãå復ä¸è½ãªã¾ã§ã«å£ãã¦ããç¶æ³ã§ãæ´æ°ãã°ã ããä¿¡é ¼ã§ããã¨ãããã¨ã¯ãæ³å®ãã¥ããããã°ãéç¨ãã¹ã§ãã¼ã¿ãã¼ã¹ãã¡ã¤ã«ãæ¶ãã¦ãã¾ã£ãå ´åã®ãã¼ã«ããã¯ã«ã¯å½¹ç«ã¤ãããããªããããããè¨ã£ããæ´æ°ãã°ã®ç®¡çã§ãã°ããã¹ãããå¯è½æ§ãããã®ã§ãå®ç¨ä¸ã§å©ç¹ããããã¨ããã¨å¾®å¦ã ã
ã¨ã¯ãããããã§ããå®éç¨ä¸ã¯ãããã¯ã¢ãããã¡ã¤ã«ãä½ããã°ãªããªããã¨ãå¤ããæçµçã«ã¯éã«ç´çµããå´åã¨è¨ç®ã³ã¹ããæãã¦ã§ããå®å¿ã¨ä¿¡é ¼ãè²·ããã°ãªããããã«ããã¯ã¢ãããä½ãããã«ã·ã¹ãã ã®ãã¦ã³ã¿ã¤ã ãã§ããããã¹ã«ã¼ããããè½ã¡ãæé帯ãä½ããããªãå ´åã¯ãæ´æ°ãã°ã使ã£ãã¤ã³ã¯ãªã¡ã³ã¿ã«ããã¯ã¢ããã®ä½æãæç¨ã ãä½æããããã¯ã¢ãããã¡ã¤ã«ã¯ãå¥ãµã¼ãã¾ãã¯å¥ã¹ãã¬ã¼ã¸ã«è»¢éããã¹ãã ãããã§åãã¦ããã·ã³ãã¹ãã¬ã¼ã¸ãå£ããäºæ ã«åãããã¨ãã§ãããã¡ã¤ã³ã®ãã¼ã¿ãã¼ã¹ãå£ããã®ã«åãã¹ãã¬ã¼ã¸ã«ããæ´æ°ãã°ãçãã¦ãã¦ãææ°ç¶æ ã«è¿½å¾ã§ããããããããªããã®ã¯ä»å 価å¤ã§ã¯ããããããã«ä¾åãããµã¼ãã¹ãè¨è¨ããã¹ãã§ã¯ãªãã
çµå±ã®ã¨ããããã¼ãã¦ã§ã¢ã®æ éã«èããããã«ã¯ãã¼ãã¦ã§ã¢ãåé·åãããããªããããããã¼ã¿ãã¼ã¹ã®æèã§å®ç¾ããã®ããæ´æ°ãã°ã®å³æ転éæ©è½ã§ããã¨ããã®ãã¬ããªã±ã¼ã·ã§ã³æ©è½ã§ããã次åãããããããTkrzw-RPCã«ã¬ããªã±ã¼ã·ã§ã³ãå®è£ ãããã