英文:
How to setup ArangoDB replication via the ArangoDB Go driver
问题
我需要使用一个辅助数据库来设置一个简单的复制模式。我发现可以使用arangosh
来使用以下命令进行设置:
db._useDatabase("myDB");
require("@arangodb/replication").setupReplication({
endpoint: "tcp://main-server:8529",
username: "user",
password: "pass",
verbose: false,
includeSystem: false,
incremental: true,
autoResync: false,
autoStart: true,
restrictType: "include",
restrictCollections: [ "Products" ]
});
然而,这个设置似乎不能持久化。连接中断或服务器重启会导致它消失。
因此,我想在我的Go程序中设置一些监控和重新建立复制的功能。
我在ArangoDB网站的手册页面和Go驱动程序文档中搜索,但没有找到任何可以使用驱动程序在Go中运行上述设置的方法。
此外,我没有找到如何与arangosh
进行交互,并可能运行上述的JS代码并获取结果。是否可以使用Go驱动程序实现这一点?
英文:
I need to set up a simple replication schema with a secondary database. I figured out that using arangosh
I can set it up with the following commands:
db._useDatabase("myDB");
require("@arangodb/replication").setupReplication({
endpoint: "tcp://main-server:8529",
username: "user",
password: "pass",
verbose: false,
includeSystem: false,
incremental: true,
autoResync: false,
autoStart: true,
restrictType: "include",
restrictCollections: [ "Products" ]
});
This setup, however does not seem to persist. Connection going down, or server restarts make it disappear.
So, I would like to set up some monitoring and re-establishment of the replication in my Go program.
I searched both the ArangoDB website Manual pages, and Go driver documentation but I could not find anything that would allow me to run the above setup in Go using the driver.
Additionally, I didn't find how I could interface with arangosh
, and possibly run the JS code above and get the results. Is that possible somehow using the Go driver?
答案1
得分: 1
我意外地找到了一个解决方案。
Golang驱动程序不提供此功能。但是Arango有一个非常简单的基于HTTP的API,允许访问数据库引擎的所有功能和特性。
这是我使用的文档链接:https://www.arangodb.com/docs/3.8/http/index.html(我使用的是3.8版本,因为之后我需要的复制类型不再是社区版的一部分)。
设置复制只需要两个步骤:
- 发送PUT请求到
/_db/*yourDBname*/_api/replication/applier-config
,带上JSON负载:
{
"endpoint":"tcp://serverIP:8529",
"database":"yourDBname",
"username":"root",
"password":"password",
"autoResync": true,
"autostart":true
}
-
然后再发送一个PUT请求到
/_db/*yourDBname*/_api/replication/applier-start
,以实际开始复制。这个请求不需要任何负载。 -
如果想查看进展情况,可以发送GET请求到
/_db/*yourDBname*/_api/replication/applier-state
。
所有这些请求都需要一个JWT令牌,你可以通过发送POST请求到/_open/auth
并带上以下负载来获取:
{
"username": "user",
"password": "passwd"
}
你收到的令牌需要作为Bearer令牌包含在HTTP头中。非常简单。
英文:
I accidentally found a solution to this.
The Golang driver does not provide this functionality. But Arango has a pretty simple HTTP based API which allows access to all functions and features of the database engine.
Here's the link to the documentation I used: https://www.arangodb.com/docs/3.8/http/index.html
(I'm using version 3.8 because after that the type of replication I needed was no longer part of the community edition).
Setting up a replication requires just two steps:
- PUT request to the /_db/yourDBname/_api/replication/applier-config with a JSON payload:
{
"endpoint":"tcp://serverIP:8529",
"database":"yourDBname",
"username":"root",
"password":"password",
"autoResync": true,
"autostart":true
}
-
And another PUT request to get the replication actually started, to /_db/yourDBname/_api/replication/applier-start . This one doesn't need any payload
-
And to see how things are going you can do a GET request to /_db/yourDBname/_api/replication/applier-state
All these requests need a JWT token that you can get with a POST request to /_open/auth with a payload of:
{
"username": "user",
"password": "passwd"
}
The token you receive will need to be included in the HTTP header as a bearer token. Pretty simple.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论