Categorygithub.com/rpcxio/basalt
modulepackage
0.0.0-20200813040018-a7e186f1ae4c
Repository: https://github.com/rpcxio/basalt.git
Documentation: pkg.go.dev

# README

基于Raft的数据一致性分布式的 bitmap 服务

bitmap(位图)技术是数据库、大数据和互联网业务等场景下经常使用的一种技术。

  • 存在性判断
    • 爬虫url去重
    • 垃圾邮件过滤
    • 用户已阅读
    • 用户已赞
    • ...
  • 去重
  • 数据库
  • 大数据计算

架构图

支持三种协议读写: HTTPredcisrpcx

操作可以发给任意节点,但最终是由raft leader节点进行操作。 操作可以选择任意的节点进行读取。

服务

进入cmd/server, 运行go run server.go启动一个bitmap服务。

它同时支持三种服务:

  • rpcx: 你可以使用rpcx服务获取高性能的网络调用, cmd/rpcx_client是一个rpcx客户端的demo
  • redis: 你可以使用redis客户端访问Bitmap服务(如果你的redis client支持自定义命令), 方便兼容redis调用代码, cmd/redis_client是redis demo
  • http: 通过http服务调用,调用简单,支持各种编程语言和脚本,cmd/http_client/curl.sh是通过curl调用服务

集群模式

支持raft集群模式: basalt集群

API接口

basalt位图服务支持三种接口模式:

  • HTTP API: 通过http api的方式进行访问
  • Redis模式: 扩展了redis命令,可以通过redis client进行访问
  • rpcx模式: 可以通过rpcx框架进行访问

Redis命令

  • ping: ping-pong消息
  • quit: 退出连接
  • bmadd name value: 在名为name的bitmap增加一个uint32值value
  • bmaddmany name value1 value2 value3...: 为名为name的bitmap增加一批值
  • bmdel name value: 在名为name的bitmap删除一个uint32值value
  • bmdrop name: 删除名为name的bitmap
  • bmclear name: 清空名为name的bitmap
  • bmcard name: 获取为name的bitmap包含的元素数
  • bmexists name value: 检查uint32值value是否存在于名为name的bitmap中,整数1代表存在,0代表不存在
  • bminter name1 name2 name3...: 求几个bitmap的交集,返回交集的uint32整数列表
  • bminterstore dst name1 name2 name3...: 求几个bitmap(name1name2name3...)的交集,并将结果保存到dst
  • bmunion name1 name2 name3...: 求几个bitmap的并集,返回并集的uint32整数列表
  • bmunionstore dst name1 name2 name3...: 求几个bitmap(name1name2name3...)的并集,并将结果保存到dst
  • bmxor name1 name2.: 求两个bitmap的xor集(双方不共有的集合,相当于并集减交集),返回xor集的uint32整数列表
  • bmxorstore dst name1 name2: 求两个bitmap的xor集,并将结果保存到dst
  • bmdiff name1 name2: 求name1中和name2没有交集的数据,返回结果的uint32整数列表
  • bmdiffstore dst name1 name2: 求name1中和name2没有交集的数据,并将结果保存到dst
  • bmstats name: 返回name的bitmap的统计信息

rpcx 服务

查看 godoc以了解提供的rpcx服务

HTTP 服务

HTTP 服务提供和 redis、rpcx服务相同的功能,通过http调用就可以访问Bitmap服务。

所有的参数都是在路径中提供,路径格式为/action/param1/param2。 复数形式valuesnames包含多个元素,元素以逗号,分隔。

为了简化操作,所有的http服务都是通过GET方法提供的。

返回的HTTP StatusCode代表的含义如下:

  • 200 代表OK存在
  • 400 代表参数不对,比如应该是uint32格式,结果却是无法解析的字符串
  • 404 代表不存在
  • 500 代表内部处理错误

HTTP服务路径列表如下:

  • /add/:name/:value
  • /addmany/:name/:values
  • /remove/:name/:value
  • /drop/:name
  • /clear/:name
  • /exists/:name/:value
  • /card/:name
  • /inter/:names
  • /interstore/:dst/:names
  • /union/:names
  • /unionstore/:dst/:names
  • /xor/:name1/:name2
  • /xorstore/:dst/:name1/:name2
  • /diff/:name1/:name2
  • /diffstore/:dst/:name1/:name2
  • /stats/:name

例子

以微博关注关系数据集做例子,我们使用Bitmap服务来存储某人是否关注了某人,以及两人是否互相关注。

例子参看 weibo_follow

Roadmap

  • Multiple-key Bitmap
  • rpcx services for Bitmap
  • HTTP services for Bitmap
  • Redis services for Bitmap
  • Persistence
  • Cluster mode

Credits

# Packages

No description provided by the author
No description provided by the author

# Functions

NewBitmaps creates a Bitmaps.
newRaftNode initiates a raft instance and returns a committed log entry channel and error channel.
No description provided by the author
NewServer returns a server.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

Errors for bitmaps.

# Structs

No description provided by the author
Bitmap is the goroutine-safe bitmap.
BitmapDstAndPairRequest contains destination and the name of two bitmaps.
BitmapPairRequest contains the name of two bitmaps.
Bitmaps contains all bitmaps of namespace.
BitmapStoreRequest contains the name of destination and names of bitmaps.
BitmapValueRequest contains the name of bitmap and value.
BitmapValuesRequest contains the name of bitmap and values.
HTTPService is a http service.
No description provided by the author
RedisService is a redis service only supports bitmap commands.
RpcxBitmapService provides the rpcx service for Bitmaps.
Server is the bitmap server that supports multiple services.
No description provided by the author

# Interfaces

No description provided by the author

# Type aliases

ConfigRpcxOption defines the rpcx config function.
OP bitmaps operations.