2015-10-24

Tclunqlite v0.2.5

檔案放置網頁


Tclunqlite

About


This is the UnQLite extension for Tcl using the Tcl Extension Architecture (TEA).

UnQLite is a in-process software library which implements a self-contained, serverless, zero-configuration, transactional NoSQL (Key/Value store and Document-store) database engine. This extension provides an easy to use interface for accessing UnQLite database files from Tcl.

Change Log


* Update README
* Makefile.in: Add 'PTHREAD_MUTEX_RECURSIVE' undeclared solution. A workaround for glibc 2.11 issue (add _GNU_SOURCE definition)
* configure.ac: Add UNQLITE_ENABLE_THREADS flag
* generic/tclunqlite.c: Enable UnQLite multi-thread support in Unqlite_Init function
* generic/tclunqlite.c: Add unqlite -enable-threads command to check current UNQLITE_ENABLE_THREADS setting

說明


UnQLite 有支援 Thread-Safe,但是需要在編譯的時候加入 UNQLITE_ENABLE_THREADS 宣告才行(但是有可能速度會變慢)。這版只是加入相關的宣告與處理。

2015-10-22

'PTHREAD_MUTEX_RECURSIVE' undeclared solution

如果使用 glibc 2.11 的 Linux 機器,有可能會遇到這個問題(如果有使用 PTHREAD_MUTEX_RECURSIVE 的話)。

解決方法:

在 Makefile 或者是 Makefile.in (如果是使用 autoconf/configure)加入下面的判斷:

# glibc 2.11 not declaring pthread_mutexattr_settype and PTHREAD_MUTEX_RECURSIVE
# by default, causing compilation failures on some Debian and Ubuntu version.
ifneq ("$(OS)","Windows_NT")
ifneq ($(shell ldd --version | head -n 1 | grep 2.11),)
        PKG_CFLAGS += -D_GNU_SOURCE
endif
endif

這樣就可以解決問題。但是我還沒有在不是使用 glibc 2.11 的 Linux 機器與 Windows 平台上測試,確定加入以後只針對 glibc 2.11 所造成的問題。

2015-10-19

Tclunqlite v0.2.4

檔案放置網頁


Tclunqlite

About


This is the UnQLite extension for Tcl using the Tcl Extension Architecture (TEA).

UnQLite is a in-process software library which implements a self-contained, serverless, zero-configuration, transactional NoSQL (Key/Value store and Document-store) database engine. This extension provides an easy to use interface for accessing UnQLite database files from Tcl.

一些說明


主要是一些我打錯地方的小修改與整理,然後實作了 doc_current_id, doc_last_id 二個新的 command。

實作了 doc_current_id 以後,我才發現 db_current_record_id 和 Jx9 內建的函式 db_fetch 有一樣的問題,這需要修改 UnQLite 才能夠修正問題,不過我不想要直接放上去我自己硬解的版本(這樣會有分散版本的問題,而且以後有新的版本出來,我就需要 UnQLite 每個新版本出來就修改一次)。

2015-10-15

Tclunqlite v0.2.2

檔案放置網頁


Tclunqlite

About


This is the UnQLite extension for Tcl using the Tcl Extension Architecture (TEA).

UnQLite is a in-process software library which implements a self-contained, serverless, zero-configuration, transactional NoSQL database engine. This extension provides an easy to use interface for accessing UnQLite database files from Tcl.

一些說明


實作下列 command 可以存取 binary data (for value, key 仍然要用字串):

DBNAME kv_store key value ?-binary BOOLEAN?
DBNAME kv_append key value ?-binary BOOLEAN?
DBNAME kv_fetch key ?-binary BOOLEAN?
CURSORNAME getdata ?-binary BOOLEAN?

所以如果是 binary data,現在也可以使用 Tclunqlite 來下 kv_store 或者是 kv_append 然後儲存在 UnQLite 的資料庫中,然後用 kv_fetch 或者是 cursor_name getdata 拿出來。

2015-10-13

Tclunqlite v0.2.1

檔案放置網頁


Tclunqlite

一些說明


在 Tclunqlite v0.2.1 主要實作下面二個 command,主要用來測試。

DBNAME jx9_eval Jx9_script_string
DBNAME jx9_eval_file Jx9_script_file

用途就是用來執行 UnQLite 提供的 Jx9 script。二個執行的順序很像,大致是這樣的流程:
  • unqlite_compile or unqlite_compile_file
  • unqlite_vm_exec
  • unqlite_vm_release
  • 運用 unqlite_vm_config 所提供的功能,將 output buffer 的內容傳回來
然後考慮下面的 Jx9 測試 script:

if( !db_exists('users') ) { print db_create('users'); }

$zRec = [
{
   name : 'james',
   age  : 27,
   mail : 'dude@example.com'
},
{
   name : 'robert',
   age  : 35,
   mail : 'rob@example.com'
},
{
   name : 'monji',
   age  : 47,
   mail : 'monji@example.com'
},
{
  name : 'barzini',
  age  : 52,
  mail : 'barz@mobster.com'
}
];

print db_store('users',$zRec);

print db_fetch('users');
print db_fetch('users');

就可以發現,DBNAME jx9_eval_file ( 呼叫 unqlite_compile_file)執行完整個的 Jx9 script 以後,db_fetch 的結果是正常的,也就是可以正確的移往下一筆資料。

但是如果使用 DBNAME jx9_eval ( 呼叫 unqlite_compile)執行,那麼 db_fetch 就只會拿到第一筆資料,而且不會正確的移往下一筆。

經過思考,雖然沒有去 trace 這一段 code,但是我大致上認為原因是因為我在寫 jx9_eval command 的時候,都會經歷 compile, execute and release 的流程,所以原本用來記錄目前 id 的資料就被設為初始值。但是要求經歷這個流程以後還能夠記住好像也有點奇怪(因為 VM 都被我 release 了)。

如果要硬解的話,那麼就是設定一個 global variable,初始值一樣為 0。然後在 db_fetch 操作之前,覆寫回目前的 record id,並且在執行動作以後紀錄目前的值。同樣的,db_reset_record_cursor 追蹤到最源頭,在對 record id 動作的地方也做一樣的事情(將這個 global variable 設為 0),這樣就可以解決問題。但是因為使用了 global variable,所以可能會有其它的麻煩,以及可能會造成記錄不一致的問題。

不過我最後沒有放上去我硬解的做法,只有將 jx9_eval 與 jx9_eval_file 二個 command 放到套件裡。

2015-10-11

Tclunqlite v0.2

檔案放置網頁

Tclunqlite

更新

加入下面的 command:

DBNAME doc_create collection_name
DBNAME doc_fetch
DBNAME doc_fetch_id record_id
DBNAME doc_fetchall
DBNAME doc_store json_record
DBNAME doc_count
DBNAME doc_delete record_id
DBNAME doc_begin
DBNAME doc_commit
DBNAME doc_rollback
DBNAME doc_drop
DBNAME doc_close


其它

UnQLite Jx9 Built-in function db_fetch 並不會自動將 Cursor 移到下一筆,所以我在測試的時候無法拿到下一筆記錄。我不知道是我使用方式有問題,還是 UnQLite 的實作有 issue。

2015-10-09

Tclunqlite v0.1

我實作了 UnQLite 一部份的 Database Engine Handle, Key/Value Store Interfaces, Cursor Iterator Interfaces 與 Manual Transaction Manager 功能。

UnQLite 的儲存方式有二種,一種是 key-pair,一種是 JSON 文件。目前我已經實作了一部份 key-pair 方式的功能。

這是一個嘗試實作的 draft 版本,我有寫一些簡單的測試檔案進行測試目前實作的部份,不過因為沒有大量測試,所以請不要用在需要高可靠度的環境。

檔案放置網頁

Tclunqlite

About

This is the UnQLite extension for Tcl using the Tcl Extension Architecture (TEA).

UnQLite is a in-process software library which implements a self-contained, serverless, zero-configuration, transactional NoSQL database engine. This extension provides an easy to use interface for accessing UnQLite database files from Tcl.

License and version

BSD license, v0.1 (draft version)

UNIX BUILD

Building under most UNIX systems is easy, just run the configure script and then run make. For more information about the build process, see the tcl/unix/README file in the Tcl src dist. The following minimal example will install the extension in the /opt/tcl directory.

$ cd tclunqlite
$ ./configure --prefix=/opt/tcl
$ make
$ make install

WINDOWS BUILD

The recommended method to build extensions under windows is to use the Msys + Mingw build process. This provides a Unix-style build while generating native Windows binaries. Using the Msys + Mingw build tools means that you can use the same configure script as per the Unix build to create a Makefile.

Implement commands

Basic usage

unqlite DBNAME FILENAME ?-readonly BOOLEAN? ?-mmap BOOLEAN? ?-create BOOLEAN? ?-in-memory BOOLEAN? ?-nomutex BOOLEAN?
DBNAME close
DBNAME config ?-disableautocommit BOOLEAN?

Key/value features

DBNAME kv_store key value
DBNAME kv_append key value
DBNAME kv_fetch key
DBNAME kv_delete key

Transactions

DBNAME begin
DBNAME commit
DBNAME rollback

Cursors

DBNAME cursor_init CURSORNAME
CURSORNAME seek
CURSORNAME first
CURSORNAME last
CURSORNAME next
CURSORNAME prev
CURSORNAME isvalid
CURSORNAME getkey
CURSORNAME getdata
CURSORNAME delete
CURSORNAME reset
CURSORNAME release

Misc

DBNAME random_string buf_size
DBNAME version