Apache-Cassandra
Cassandra 使用笔记
Apache Cassandra 是一套开源分布式 NoSQL 数据库系统。它最初由 Facebook 开发,用于储存收件箱等简单格式数据,集 Google BigTable 的数据模型与 Amazon Dynamo 的完全分布式的架构于一身。Facebook 于 2008 年将 Cassandra 开源,此后,由于 Cassandra 良好的可扩放性,被 Digg, Twitter 等知名 Web 2.0 网站所采纳,成为了一种流行的分布式结构化数据存储方案。
https://docs.datastax.com/en/cassandra/3.0/
epoll is not available. Using NIO instead
项目启动时 Cassandra 配置报错:
2018-10-07 13:15:50.453 |-WARN [main] com.datastax.driver.core.NettyUtil [76] -| Found Netty's native epoll transport in the classpath, but epoll is not available. Using NIO instead.
java.lang.UnsatisfiedLinkError: no netty-transport-native-epoll in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867) ~[?:1.8.0_171]
at java.lang.Runtime.loadLibrary0(Runtime.java:870) ~[?:1.8.0_171]
at java.lang.System.loadLibrary(System.java:1122) ~[?:1.8.0_171]
at io.netty.util.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:189) ~[netty-common-4.0.37.Final.jar!/:4.0.37.Final]
at io.netty.channel.epoll.Native.<clinit>(Native.java:49) ~[netty-transport-native-epoll-4.0.27.Final.jar!/:4.0.27.Final]
at io.netty.channel.epoll.Epoll.<clinit>(Epoll.java:30) ~[netty-transport-native-epoll-4.0.27.Final.jar!/:4.0.27.Final]
at java.lang.Class.forName0(Native Method) ~[?:1.8.0_171]
at java.lang.Class.forName(Class.java:264) ~[?:1.8.0_171]
at com.datastax.driver.core.NettyUtil.<clinit>(NettyUtil.java:68) [cassandra-driver-core-3.1.4.jar!/:?]
at com.datastax.driver.core.NettyOptions.eventLoopGroup(NettyOptions.java:99) [cassandra-driver-core-3.1.4.jar!/:?]
at com.datastax.driver.core.Connection$Factory.<init>(Connection.java:769) [cassandra-driver-core-3.1.4.jar!/:?]
at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1410) [cassandra-driver-core-3.1.4.jar!/:?]
at com.datastax.driver.core.Cluster.init(Cluster.java:159) [cassandra-driver-core-3.1.4.jar!/:?]
at com.datastax.driver.core.Cluster.connectAsync(Cluster.java:330) [cassandra-driver-core-3.1.4.jar!/:?]
at com.datastax.driver.core.Cluster.connect(Cluster.java:280) [cassandra-driver-core-3.1.4.jar!/:?]
at org.springframework.cassandra.config.CassandraCqlSessionFactoryBean.connect(CassandraCqlSessionFactoryBean.java:100) [spring-cql-1.5.11.RELEASE.jar!/:?]
at org.springframework.cassandra.config.CassandraCqlSessionFactoryBean.afterPropertiesSet(CassandraCqlSessionFactoryBean.java:94) [spring-cql-1.5.11.RELEASE.jar!/:?]
只是个warning,不影响使用,Cassandra 会自动用 NIO 代替 epoll
How to fix the “Found Netty’s native epoll transport in the classpath, but epoll is not available. Using NIO instead” warning?
https://stackoverflow.com/questions/40746505/how-to-fix-the-found-nettys-native-epoll-transport-in-the-classpath-but-epoll
epoll
Netty Native用C++编写JNI调用的Socket Transport,与JDK的NIO相比,GC更少,性能更高。
Netty的 epoll transport使用 edge-triggered 而 JDK NIO 使用 level-triggered;
更少GC,更少synchronized;
暴露了更多的Socket配置参数,见EpollChannelOption;
注意: Netty Native跟OS相关且基于GLIBC2.10编译,目前只支持Linux (since 4.0.16)和MacOS/BSD (since 4.1.11),建议根据System.getProperty(“os.name”)和System.getProperty(“os.version”)来判断。
Native transports
https://github.com/netty/netty/wiki/Native-transports
本文来自 库昊天 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/yangguosb/article/details/79221743?utm_source=copy
资料
Cassandra简介
http://www.cnblogs.com/loveis715/p/5299495.html
Cassnadra 3.X 特性概述
https://www.ibm.com/developerworks/cn/opensource/os-cn-apache-cassandra3x1/index.html
基本操作
CREATE KEYSPACE 创建键空间
Cassandra 的存储抽象结构和数据库一样,keyspace 对应关系数据库的 database 或 schema, column family 对应于 table, 所以我们现在就和操作关系数据库一样,在连上去过后的第一步,就是创建一个 keyspace(注:如果不知道命令如何使用,打入help命令,很多东西都可以看到如何使用):
CREATE KEYSPACE IF NOT EXISTS myCas
WITH REPLICATION = {'class': 'SimpleStrategy','replication_factor':1};
class : 副本配置策略:
- SimpleStrategy 为集群指定简单的复制因子,副本不考虑机架的因素,按照 Token 放置在连续下几个节点;
- NetworkTopologyStrategy 将M个副本放置到其他的数据中心,将N-M-1的副本放置在同一数据中心的不同机架中;
http://cassandra.apache.org/doc/latest/cql/ddl.html#create-keyspace
Cassandra操作入门
https://blog.csdn.net/fenglibing/article/details/9411021
desc keyspaces 查看全部keyspace
describe keyspaces;
或
desc keyspaces;
USE keyspace 切换键空间
使用某个keyspace:use myCas;
desc tables 查询全部的table
desc tables;
创建表
官方示例:
CREATE TABLE monkeySpecies (
species text PRIMARY KEY,
common_name text,
population varint,
average_size int
) WITH comment='Important biological records'
AND read_repair_chance = 1.0;
CREATE TABLE timeline (
userid uuid,
posted_month int,
posted_time uuid,
body text,
posted_by text,
PRIMARY KEY (userid, posted_month, posted_time)
) WITH compaction = { 'class' : 'LeveledCompactionStrategy' };
CREATE TABLE loads (
machine inet,
cpu int,
mtime timeuuid,
load float,
PRIMARY KEY ((machine, cpu), mtime)
) WITH CLUSTERING ORDER BY (mtime DESC);
注意创建表的时候至少指定一个主键;
http://cassandra.apache.org/doc/latest/cql/ddl.html#create-table
删除表
drop table user;
描述一张表:desc user;
向表中插入一条记录:INSERT INTO user (id,user_name) VALUES (1,’zhangsan’);
查询表中全部数据:select * from user;
cassandra查询有很多限制,比如只能单表查询,不支持联表查询和子查询,查询条件只支持key查询和索引列查询,而且key有顺序的限制,等等;更多详情请自行阅读官方文档;
简单的条件查询:select * from user where id=1;
创建索引:create index on user(user_name);
索引列查询:select * from user where user_name=’zhangsan’;
若没有在name上创建索引,那么此查询会报错;索引列只可以用=号查询,不能使用>或<;如果想用>或<查询,可以加上ALLOW FILTERING,例如:select * from teacher where age>35 ALLOW FILTERING;如果查询条件里,有一个是根据索引查询,那其它非索引非主键字段,也可以通过加一个ALLOW FILTERING来过滤实现;
更新表中数据:update user set user_name=’lisi’ where id=2;
只支持按主键更新,也就是where后只能跟主键
删除表中记录:delete from user where id=1;
删除某条记录中的某个字段,该字段会被设成null:delete user_name from user where id=1;无论是删除某条记录,还是将某个字段置null,都只支持按主键删除,也就是where后只能跟主键;
删除自定义类型: drop type user_defined;
Cassandra入门简介
https://www.jianshu.com/p/10e033fb6c8b
Mac Homebrew安装Cassandra
安装 Cassandra - Mac OS X
Cassandra(3.1版本)在Mac上的安装比较简单,需要提前安装Homebrew, pip, python
1、安装cql,即Cassandra query language shellpip install cql
2、安装Cassandrabrew install cassandra
安装路径:/usr/local/Cellar/cassandra/
卸载Cassandra
brew uninstall cassandra
启动Cassandra
启动Cassandra后台服务brew services start cassandra
若果不需要background service,可以直接运行cassandra -f
关闭Cassandra
brew services stop cassandra
或者
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.cassandra.plist
登录cqlsh
Cassandra启动成功后,在命令行输入cqlsh,就可以愉快地写cql代码了。
Cassandra 文件目录
Cassandra的安装目录是:/usr/local/Cellar/cassandra/3.11.3
Properties: /usr/local/etc/cassandra
Logs: /usr/local/var/log/cassandra
Data: /usr/local/var/lib/cassandra/data
Cassandra 安装 - Mac OS X & Linux
http://www.myoak.info/post/12/
下一篇 Jackson
页面信息
location:
protocol
: host
: hostname
: origin
: pathname
: href
: document:
referrer
: navigator:
platform
: userAgent
: