SQLite 可以与 GlusterFS 一起使用吗?

mat*_*ath 6 high-availability sqlite

我想构建一个基于 GlusterFS 的分布式存储和自动文件复制 (AFR) 以容错方式存储用户文件。

但我也想从多个客户端访问存储在 GlusterFS 卷上的 SQLite3 数据库(因此在多个服务器上复制)。是否可以?几个客户端之间的并发是否会得到很好的处理,不会导致腐败?

或者有没有更好的 GlusterFS 替代方案来分发 SQLite3 数据库?

Ari*_*ouk 7

我写了一个sqlite_shared_fs_check.sh脚本来模拟对 sqlite3 数据库的多次读写。它应该在多台客户端机器上的同一个 GlusterFS 目录中运行。

我测试了以下配置:

  • GlusterFS 3.2 和 sqlite3 3.5.9 (ubuntu 8.10)。数据库没有损坏。
  • GlusterFS 3.2 和 sqlite3 3.6.22-1 (ubuntu 10.04)。待定。
  • Ext3 和 sqlite3 3.5.9 (ubuntu 8.10):测试同时从两个终端窗口运行。测试结束,没有任何问题。

上次测试 (ext3+sqlite3) 的结果将 POSIX 锁定不一致性归咎于 GlusterFS 3.2。

这是我用来做测试的脚本:

#!/bin/bash

function ErrorExit()
{
  echo Error: $@
  exit 1
}

# Microseconds
timeout=5000

if [ ! -f test.sqlite3 ];
then
  touch test.sqlite3
  echo 'create table test1 (id integer primary key autoincrement,datetime text,hostname text);' | sqlite3 test.sqlite3 || ErrorExit "Create"
fi

if [ ! -f /tmp/insert.sql ];
then
  echo .timeout $timeout > /tmp/insert.sql
  echo "insert into test1 values (NULL,datetime('now','localtime'),'$HOSTNAME');" >> /tmp/insert.sql
fi

if [ ! -f select.sql ];
then
  echo .timeout $timeout > select.sql
  echo "select * from test1 order by id desc limit 1;" >> select.sql
fi

if [ ! -f count.sql ];
then
  echo .timeout $timeout > count.sql
  echo "select count(*) from test1;" >> count.sql
fi

i=1
while [ $i -le 1000 ];
do
  lockfile-create --retry 20 test.sqlite3 || echo -n "?"
  sqlite3 test.sqlite3 < /tmp/insert.sql
  lockfile-remove test.sqlite3

  # Sleep a bit to allow other users
  sleep 0.5
  lockfile-create --retry 20 test.sqlite3 || echo -n "?"
  sqlite3 test.sqlite3 < select.sql >/dev/null || ErrorExit select [$i]
  sqlite3 test.sqlite3 < count.sql >/dev/null || ErrorExit count [$i]
  lockfile-remove test.sqlite3
  let i++
  echo -n "."
done
Run Code Online (Sandbox Code Playgroud)

请注意,我必须使用 lockfile-create 实用程序来获取对数据库的锁定,因为 sqlite 的内部锁定不够可靠。


小智 4

即使在复制模式下,GlusterFS也支持完整的POSIX文件/记录级锁定。它应该工作正常。