cassandra

简单实用算法—分布式自增ID算法snowflake(雪花算法)

一个人想着一个人 提交于 2020-07-23 23:24:45
算法概述 分布式系统中,有一些需要使用全局唯一ID的场景,这种时候为了防止ID冲突可以使用36位的UUID,但是UUID有一些缺点,首先他相对比较长,另外UUID一般是无序的。有些时候我们希望能使用一种简单一些的ID,并且希望ID能够按照时间有序生成。而twitter的snowflake解决了这种需求,最初Twitter把存储系统从MySQL迁移到Cassandra,因为Cassandra没有顺序ID生成机制,所以开发了这样一套全局唯一ID生成服务。 该项目地址(Scala实现): https://github.com/twitter/snowflake python版项目地址: https://github.com/erans/pysnowflake ID结构 Snowflake生成的是Long类型的ID,一个Long类型占8个字节,每个字节占8比特,也就是说一个Long类型占64个比特。 snowflake的结构如下(每部分用-分开): 注:上图的 工作机器id(10比特)=数据中心(占左5比特)+ 机器ID(占右5比特) Snowflake ID组成结构:正数位(占1比特)+ 时间戳(占41比特)+ 数据中心(占5比特)+ 机器ID(占5比特)+ 自增值(占12比特) 第一位为未使用,接下来的41位为毫秒级时间(41位的长度可以使用69年)

How do i check cassandra and solr is up?

只谈情不闲聊 提交于 2020-07-22 17:56:51
问题 I just installed datastax 2.2.2 on my ubuntu:12.04 machine from tarball I started services using bin/dse cassandra -s . I din't set any env variables.But it starts the service. bin/dse/bin/nodetool status It lists out list of valid commands where status is not there. How do i verify my cassandra and solr is up? AM i missing something? ANy ideas? 回答1: nodetool status should work. DSE 4.6 is the latest version, why are you on 2.2? Watch your system and output logs as the node starts up to see

Cassandra Batch statement-Multiple tables

匆匆过客 提交于 2020-07-18 11:32:45
问题 I want to use batch statement to delete a row from 3 tables in my database to ensure atomicity. The partition key is going to be the same in all the 3 tables. In all the examples that I read about batch statements, all the queries were for a single table? In my case, is it a good idea to use batch statements? Or, should I avoid it? I'm using Cassandra-3.11.2 and I execute my queries using the C++ driver. 回答1: Yes, you can use batch to ensure atomicity. Single partition batches are faster

How to check that Cassandra is ready

六月ゝ 毕业季﹏ 提交于 2020-07-15 07:00:23
问题 I have a Cassandra running in a Docker and I want to launch a CQL script when the database is ready. I tried checking the port to detect when it's ready : while ! nc -z localhost 7199; do sleep 1 done echo "Cassandra is ready" cqlsh -f ./createTables.cql But the port is opened before the database is really ready, and the cqlsh therefore fails. How to properly check the Cassandra status and launch the script ? Thanks in advance. 回答1: First you need to wait on another port - 9042 - this is a

How to check that Cassandra is ready

五迷三道 提交于 2020-07-15 06:59:40
问题 I have a Cassandra running in a Docker and I want to launch a CQL script when the database is ready. I tried checking the port to detect when it's ready : while ! nc -z localhost 7199; do sleep 1 done echo "Cassandra is ready" cqlsh -f ./createTables.cql But the port is opened before the database is really ready, and the cqlsh therefore fails. How to properly check the Cassandra status and launch the script ? Thanks in advance. 回答1: First you need to wait on another port - 9042 - this is a

How to check that Cassandra is ready

冷暖自知 提交于 2020-07-15 06:59:18
问题 I have a Cassandra running in a Docker and I want to launch a CQL script when the database is ready. I tried checking the port to detect when it's ready : while ! nc -z localhost 7199; do sleep 1 done echo "Cassandra is ready" cqlsh -f ./createTables.cql But the port is opened before the database is really ready, and the cqlsh therefore fails. How to properly check the Cassandra status and launch the script ? Thanks in advance. 回答1: First you need to wait on another port - 9042 - this is a

Spring-data-cassandra: Error creating bean with name 'sessionFactory' and Cannot resolve reference to bean 'cassandraTemplate'

喜你入骨 提交于 2020-07-10 08:34:11
问题 I have a springboot app, in which I am connecting to cassandra DB. My pom.xml: parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.6.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-cassandra</artifactId> </dependency> The cassandraConfig definitition: @Configuration @PropertySource("file:///Users

Codec not found for requested operation: [map<varchar, int> <-> java.util.Map]; issue Apache Cassandra

浪尽此生 提交于 2020-07-09 05:30:23
问题 I have a table with the fields CREATE TABLE app_category_agg ( category text, app_count int, sp_count int, subscriber_count int, window_revenue bigint, top_apps frozen <list<map<text,int>>>, PRIMARY KEY (category) ); when I try to map it to kotlin model @Table("app_category_agg") class AppCategoryAggData { @PrimaryKeyColumn(name = "category", ordinal = 0, type = PrimaryKeyType.PARTITIONED) lateinit var category: String @Column("app_count") var appCount: Int = 0 @Column("sp_count") var spCount

Tombstoned cells without DELETE

China☆狼群 提交于 2020-06-29 13:10:16
问题 I'm running Cassandra cluster Software version: 2.0.9 Nodes: 3 Replication factor: 2 I'm having a very simple table where I insert and update data. CREATE TABLE link_list ( url text, visited boolean, PRIMARY KEY ((url)) ); There is no expire on rows and I'm not doing any DELETEs. As soon as I run my application it quickly slows down due to the increasing number of tombstoned cells: Read 3 live and 535 tombstoned cells It gets up to thousands in few minutes. My question is what is responsible

Spark get ttl column from cassandra

两盒软妹~` 提交于 2020-06-29 06:02:11
问题 I am trying to get the ttl column from cassandra, but so far I couldn't make it work. Here is what I tried so far: SparkSession sparkSession = SparkSession.builder() .appName("Spark Sql Job").master("local[*]") .config("spark.sql.warehouse.dir", "file:///c:/tmp/spark-warehouse") .config("spark.cassandra.connection.host", "localhost") .config("spark.cassandra.connection.port", "9042") .getOrCreate(); SQLContext sqlCtx = sparkSession.sqlContext(); Dataset<Row> rowsDataset = sqlCtx.read()