存储过程voltDB 部署与实现

voltdb  时间:2021-01-26  阅读:()

目 录

1 VoltDB简介. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2

2 VoltDB部署安装环境. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2

2.1.安装环境要求. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2

2.2.安装VoltDB. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3

2.3.VoltDB是怎么工作的. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3

3.一个简单应用Hel lo,World!. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5

3.1创建一个目录用来存放项目所有源文件. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5

3.2定义数据库结构. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5

3.3创建存储过程文件用来插入记录文件名为Insert. java. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5

3.4创建存储过程用来查询记录,文件名为Select.java. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6

3.5创建客户端源文件名为Cl ient.java. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6

3.6创建工程定义文件project.xml,该文件用来定义数据库表和存储过程。. . . . . . . . . . . . . . . . . .7

3.7有了这些源文件和定义文件现在可以编译了过程如下. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8

3.8.定义系统配置. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8

3.9.运行Hel loWorld. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9

1 VoltDB简介

VoltDB是StoneBra ker最新研究成果是一个优化吞吐率的高性能集群开源SQLRDBMS支持ACID。从硬件上看 VoltDB基于PC+以太网+本地存储从体系结构上看其内部是一个ShareNothing的内存数据库通过并行单线程来保证事务一致性和高性能所有事务被实现为Java存储过程所有存储过程事务均全局有序 由于避免了锁的使用因此可以保证每个事务在所有分区上并行执行完成后才继续执行下一个事务事务不会乱序执行。存储过程内部支持分组、多路Join、聚合、函数等等如果希望提高吞吐率使用单事务多SQL可以有效提高吞吐率。 Volt DB的可靠性通过冗余和自动恢复来保证。

VoltDB值得关注的一个特性是自动数据分区数据表会被自动分配到集群节点。可以看成是传统Sharding的升级、整合版本。另外一个特性是自动快照这样在一个事务内部无需进行IO操作可以在微秒级别完成事务据说性能提高50倍。第三个特性是异步事务提交。从某种意义上看 VoltDB是一个共享内存的集群有些像此前有人提到的“Ram Cloud“。 VoltDB的系统性能据说在几个节点就可以达到百万TPS VoltDB支持多节点并行事务处理理论上不存在节点上限不过VoltDB开发人员最大测试集群是20个节点。

2 VoltDB部署安装环境

2.1.安装环境要求

Operating System VoltDB requires a 64-bit Linux-based operating system.Kits are built andqualified on CentOS version 5.6 and Ubuntu versions 10.4 and 10.10.

Development builds are also available for Macintosh OSX 10.61.

CPU•Dual core2 x86_64processor

•64bit

• 1.6 GHz

Memory 4 Gbytes3

Java Sun JDK 6 update 20 or later

Required Software NTP4

Recommended Software Ant 1.7 or later

Eclipse 3.x(or other Java IDE)

Footnotes:

1.CentOS 5.6 and later and Ubuntu 10.4 and later are the only officially supported operating systemsfor VoltDB.However,VoltDB is tested on several other POSIX-compliant and Linux-based 64-bitoperating systems, including Macintosh OSX 10.6.

2.Dual core processors are a minimum requirement.Four or eight physical cores are recommended foroptimalperformance.

3.Memory requirements are very specific to the storage needs of the application and the number ofn o des

in the cluster.However,4 Gigabytes should be considered a minimum configuration.

4.NTP minimizes time differences between nodes in a database cluster,which is critical for VoltDB.Allnodes ofthe cluster should be configured to synchronize against the same NTP server.Using asingle local NTP server is recommended,but not required.

2.2.安装VoltDB

下载安装包

# wget http://community.voltdb.com/sites/default/files/archive/2.5/LINUX-vo ltdb-2.5.tar.g z安装VoltDB到一个开发服务环境

# sudo tar -zxvf LINUX-voltdb-2.5.tar.gz -C /opt

# cd /opt

# sudo mv LINUX-voltdb-2.5/ voltdb

2.3.VoltD B是怎么工作的

VoltDB有如下图3.1组件

SQL Schema定义了数据库的布局。 VoltDB使用标准的SQL DDL语法来定义数据库模式。Store Procedures:存储过程定义了如何使用数据库。所有的数据请求都被存储过程执行

存储过程使用Java和SQL定义。

Client Application:应用客户端调用存储过程去执行数据库请求并调用定义在VoltDB客户端库函数。

VoltDB Project File:该文件指定了存储过程和模式的路径还包括一些额外的应用信息。被用来编译得到结果的VoltDB应用目录。

ApplicationCatalog:应用程序目录结合了部署集群的配置信息用来创建运行时数据库实例。

3.一个简单应用Hello,World!

在Linux下现在有许多开发环境IDE可用,为了简单此例仅使用了java(jre),Vo ltDB,和一个文本编辑器。 VoltDB是一个数据库用来从数据表存储和获得数据我们在这个应用用数据库存储“He l lo”和“W o rld”并获得它们。我用了不同的语言来表示这连个字段语言设为主键。

3.1.创建一个目录用来存放项目所有源文件

#mkdir h e llo world

#c d h e llo wo r ld

3.2.定义数据库结构

CREATE TABLE HELLOWORLD (

HELLO VARCHAR(15) ,

VOLTDB VARCHAR(15) ,

DIALECT VARCHAR(15) NOT NULL,

PRIMARY KEY (DIALECT)

) ;

3. 3.创建存储过程文件用来插入记录 文件名为Insert. java

# nano Insert. java

编辑为如下import org.voltdb.*;

@ProcInfo(partitionInfo = "HELLOWORLD.DIALECT: 2",singlePartition = true

)public class Insert extends VoltProcedure {public final SQLStmt sql = new SQLStmt(

"INSERT INTO HELLOWORLD VALUES (?, ?, ?) ; "

) ;public VoltTable[ ] run( String hello,

String voltdb,

String language)throws VoltAbortException {voltQueueSQL( sql, hello, world, language ) ;voltExecuteSQL( ) ;

return null;

}

}

3.4创建存储过程用来查询记录,文件名为Select.java# nano Select. java

编辑成如下import org.voltdb.*;

@ProcInfo(partitionInfo = "HELLOWORLD.DIALECT: 0",singlePartition = true

)public class Select extends VoltProcedure {public final SQLStmt sql = new SQLStmt(

"SELECT HELLO, WORLD FROM HELLOWORLD " +

" WHERE DIALECT = ?; "

) ;public VoltTable[ ] run( String language)throws VoltAbortException {voltQueueSQL( sql, language ) ;return voltExecuteSQL( ) ;

}

}

3.5.创建客户端源文件名为Client.java

#java Client.java

源码编辑为import org.voltdb.*;import org.voltdb.client.*;public class Client {public static void main(String[ ] args) throws Exception {/*

* Instantiate a client and connect to the database.

*/org.voltdb.client.Client myApp;myApp = ClientFactory.createClient( ) ;myApp.createConnection("localhost") ;

/*

* Load the database.

*/

myApp.callProcedure("Insert", "Hello", "World", "English") ;myApp.callProcedure("Insert", "Bonjour", "Monde", "French") ;myApp.callProcedure("Insert", "Hola", "Mundo", "Spanish") ;myApp.callProcedure("Insert", "Hej", "Verden", "Danish") ;myApp.callProcedure("Insert", "Ciao", "Mondo", "Italian") ;

/*

* Retrieve the message.

*/final ClientResponse response = myApp.callProcedure("Select",

"Spanish") ;if (response.getStatus ( ) != ClientResponse.SUCCESS) {

System.err.println(response.getStatusString( ) ) ;

System.exit(-1) ;

}final VoltTable results [ ] = response.getResults ( ) ;if (results.length == 0 | | results [0] .getRowCount( ) != 1) {

System.out.printf("I can't say Hello in that language. \n") ;

System.exit(-1) ;

}

VoltTable resultTable = results [0] ;

VoltTableRow row = resultTable.fetchRow(0) ;

System.out.printf("%s, %s! \n", row.getString("hello") ,row.getString("world") ) ;

}

}

3.6.创建工程定义文件project.xml,该文件用来定义数据库表和存储过程。

# nano project.xml

源文件为

<?xml version="1.0"?>

<project>

<database>

<schemas>

<schema path='helloworld.sql' />

</schemas>

<procedures>

<procedure class='Insert' />

<procedure class='Select' />

</procedures>

<partitions>

<partition table='HELLOWORLD' column='DIALECT' />

</partitions>

</database>

</project>

编辑保存。

3.7.有了这些源文件和定义文件现在可以编译了过程如下cd $HOME/helloworld

要将voltdb路径添加到类路径的环境变量重

# CLASSPATH=" ./:/opt/voltdb/lib/*:/opt/voltdb/voltdb/*"

# export CLASSPATH

接下来分别编译Client. java, Insert. java,Select. java文件

# javac Client. java

# javac Insert. java

# javac Select. java

最后是创建应用程序目录生产helloworld. jar文件

# java org.voltdb.compiler.VoltCompiler project.xml helloworld. jar

3.8.定义系统配置

当编译好源文件和创建好应用程序目录接下来就是创建数据库和运行应用程序了最后一步的目的是配置数据库和硬件环境

The number of servers that willbe used//定义数据库服务器数量

The number of sites per server

件名为deployment.xml

# nano deployment.xml

<?xml version="1.0"?>

<deployment>

<cluster hostcount="1"sitesperhost="2"

/>

<httpd enabled="true" port=”8081”>

<jsonapi enabled="true" />

</httpd>

</deployment>

3.9.运行HelloWorld

运行VoltDB应用包含两个分开的过程开启数据库服务和运行客户端应用首先在一个终端开启数据库服务

#java -Djava.library.path=/opt/voltdb/voltdb \org.voltdb.VoltDB \catalog helloworld. jar \deployment deployment.xml \leader localhost

如果服务开启成功 VoltDB将显示有关信息

……

……

再启动一个终端执行如下命令

# java Client

运行成功

NameCheap新注册.COM域名$5.98

随着自媒体和短视频的发展,确实对于传统的PC独立网站影响比较大的。我们可以看到云服务器商家的各种促销折扣活动,我们也看到传统域名商的轮番新注册和转入的促销,到现在这个状态已经不能说这些商家的为用户考虑,而是在不断的抢夺同行的客户。我们看到Namecheap商家新注册域名和转入活动一个接一个。如果我们有需要新注册.COM域名的,只需要5.98美元。优惠码:NEWCOM598。同时有赠送2个月免费域名...

香港 1核 1G 5M 22元/月 美国 1核 512M 15M 19.36元/月 轻云互联

轻云互联成立于2018年的国人商家,广州轻云互联网络科技有限公司旗下品牌,主要从事VPS、虚拟主机等云计算产品业务,适合建站、新手上车的值得选择,香港三网直连(电信CN2GIA联通移动CN2直连);美国圣何塞(回程三网CN2GIA)线路,所有产品均采用KVM虚拟技术架构,高效售后保障,稳定多年,高性能可用,网络优质,为您的业务保驾护航。官方网站:点击进入广州轻云网络科技有限公司活动规则:用户购买任...

Virtono:€23.7/年,KVM-2GB/25GB/2TB/洛杉矶&达拉斯&纽约&罗马尼亚等

Virtono最近推出了夏季促销活动,为月付、季付、半年付等提供9折优惠码,年付已直接5折,而且下单后在LET回复订单号还能获得双倍内存,不限制付款周期。这是一家成立于2014年的国外VPS主机商,提供VPS和服务器租用等产品,商家支持PayPal、信用卡、支付宝等国内外付款方式,可选数据中心包括罗马尼亚、美国洛杉矶、达拉斯、迈阿密、英国和德国等。下面列出几款VPS主机配置信息,请留意,下列配置中...

voltdb为你推荐
金士顿内存真假关于金士顿内存的真伪二手车网站哪个好卖二手车网站哪个好核芯显卡与独立显卡哪个好核芯显卡和独立显卡哪个好?请直接点谢谢啦!手机管家哪个好手机管家哪个好股票软件哪个好请问:免费的模拟炒股软件哪个好?看书软件哪个好手机读书软件哪个好用?网络机顶盒哪个好哪个品牌的网络机顶盒好用?qq空间登录qq空间如何登陆辽宁联通网上营业厅网中国联通的初始服务密码一般是多少dns服务器未响应DNS服务器未响应是什么意思?
西安服务器租用 vps动态ip 企业主机 香港加速器 免费ftp空间 42u机柜尺寸 evssl证书 2017年黑色星期五 ubuntu更新源 天猫双十一抢红包 双拼域名 789电视 91vps 世界测速 linux服务器维护 河南移动m值兑换 太原网通测速平台 shopex主机 华为云盘 shuang12 更多