Cassandra DB中的日期插入:不平凡的1小时班次问题 [英] Date insertion in Cassandra DB: non-trivial 1h shift issue

查看:157
本文介绍了Cassandra DB中的日期插入:不平凡的1小时班次问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点绝望的这个问题...我不知道如何面对它。

I am a bit desperate about this problem... I have no idea how to face it.

这是一个更简单的方法来看这个问题: / p>

如果我插入cql查询是:

Here is a simpler way to look at this problem:


开始使用一致性插入进入my_table(id,'2014-04-11 8:00:00',...,'2014-04-15 10:00:00')值('2036548',3.15,...,4.11)APPLY BATCH

If my insert cql query is:

...我的数据请求cql查询是:

"BEGIN BATCH USING CONSISTENCY ONE insert into my_table(id,'2014-04-11 8:00:00',...,'2014-04-15 10:00:00') values ('2036548',3.15,...,4.11) APPLY BATCH"


选择FIRST 1000002014-04-01 0:00:00'..'2014-04-16 0:00:00'from my_table where id = 2036548

...and my data request cql query is:

...为什么插入日期 2014-04-15 10 :00:00 从Cassandra将其更新为2014-04-15 11 :00:00

"Select FIRST 100000 '2014-04-01 0:00:00'..'2014-04-16 0:00:00' from my_table where id=2036548"

日期拉vb.net中的代码是:

...why does the inserted date 2014-04-15 10:00:00 changes to 2014-04-15 11:00:00 when pullling it from Cassandra?

The date pulling code in vb.net is:

... PHP中相同的东西:

Public Shared Function getCassandraDate(ByVal value As Byte()) As Date Dim buffer As Byte() = New Byte(value.Length - 1) {} value.CopyTo(buffer, 0) Array.Reverse(buffer) Dim ticks As Long = BitConverter.ToInt64(buffer, 0) Dim dateTime As New System.DateTime(1970, 1, 1, 0, 0, 0, _ 0) dateTime = dateTime.AddMilliseconds(ticks) Return dateTime.ToLocalTime End Function

...same thing in PHP:






更多详细信息

加工链:

(1)。通过.NET插入Cassandra

Processing chain:

(2)。 Cassandra数据存储

(1). insertion to Cassandra through .NET

(3)。从PHP或.NET中获取数据

(2). Cassandra data storage

问题:

至于今天日期是<04>

Problem:

2014-04-15 10 :00:00 在步骤(1) :00:00 在步骤(3)。

As for today, a date being 2014-04-15 10:00:00 in step (1), will come out as 2014-04-15 11:00:00 in step (3).

详细信息:

(关于此链中的日期格式)

(regarding the date format in this chain)

(1)。本地时间在.NET(时区:欧洲/巴黎)。正在执行的插入cql:使用一致性的BEGIN BATCH插入my_table(id,'2014-04-11 8:00:00',...,'2014-04-15 10: 00:00')值('2036548',3.15,...,4.11)APPLY BATCH

(1). Local time in .NET (Timezone: "Europe/Paris"). Insertion cql that is being executed: "BEGIN BATCH USING CONSISTENCY ONE insert into my_table(id,'2014-04-11 8:00:00',...,'2014-04-15 10:00:00') values ('2036548',3.15,...,4.11) APPLY BATCH"

(2)。 我不知道Cassandra在这里做什么...?

(3)。示例cql查询以提取数据:选择FIRST 100000'2014-04-01 0:00:00'..'2014-04-16 0:00:00'from my_table where id = 2036548。在php中: date_default_timezone_set(Europe / Paris); $ str_time = date('Y-m-d H:i:s',$ time); 。在.NET中: dateTime.ToLocalTime

(3). Example of cql query to pull the data: "Select FIRST 100000 '2014-04-01 0:00:00'..'2014-04-16 0:00:00' from my_table where id=2036548". In php: date_default_timezone_set("Europe/Paris"); $str_time = date('Y-m-d H:i:s',$time);. In .NET: dateTime.ToLocalTime.

额外信息:

我认为在几个星期前夏令时改变之前,效果很好。但是我无法确定这一点。

I think it worked well before the daylight saving time change some weeks ago. But I can not be sure about that.

如果在步骤(1)中,如果在插入之前将日期更改为UTC, 04-15 10 :00:00 将成为<04> > :00:00

If in step (1), if I changed the date to de date to UTC before inserting it, 2014-04-15 10:00:00 will become 2014-04-15 08:00:00 and the output will be 2014-04-15 09:00:00, which is still not correct.

我高度怀疑,这里的诀窍在步骤(1)和(2)之间,也就是说我无法理解Cassandra如何对待日期。

I highly suspect that the trick here is between steps (1) and (2), that is to say, me not being able to understand how Cassandra treats dates.

Edit1:

@Ananth的问题:

@Ananth 's questions:


Cassandra和客户端都运行在同一个数据中心?

both cassandra and client run in the same datacenter?

这很复杂:


  • 从server1插入.NET,与server-cassandra(数据中心)不同的服务器。

  • PHP数据)在server-cassandra上运行。

  • .NET(拉数据)在server1上运行,而不是在server-cassan上

  • PHP和.NET提取相同的结果。

  • Insertion in .NET from server1, a different server from server-cassandra (datacenter).
  • PHP (to pull the data) running on server-cassandra.
  • .NET (to pull the data) running on server1, not on server-cassandra.
  • PHP and .NET pulling the same result.

<你可以在这里发布你的模式吗?

Can you post your schema here?

这里是

CREATE TABLE tsmeasures (
  id int PRIMARY KEY
) WITH
  comment='' AND
  comparator=timestamp AND
  read_repair_chance=0.100000 AND
  gc_grace_seconds=0 AND
  default_validation=double AND
  min_compaction_threshold=4 AND
  max_compaction_threshold=32 AND
  replicate_on_write='true' AND
  compaction_strategy_class='SizeTieredCompactionStrategy' AND
  compression_parameters:sstable_compression='SnappyCompressor';

Edit2:

经过测试,结果如下:


  • 实际日期:2014-04-15 17:00:00 (本地时间)

  • cql文本:'2014-04-15 15:00:00'(通过.NET完成UTC)

  • PHP Cassandra这个日期的包装=> $ ticks = 1397577600(*)打开包装是用

(通过 http://www.epochconverter.com/


  • GMT:星期二

  • 2014年4月15日16:00:00 GMT您的时区:4/15/2014 6:00:00 PM GMT + 2

这些结果对我来说没有意义...

These results makes no sense to me...

更多细节:

cql insert:

cql insert:


开始使用一致性插入到tsmeasures(id,'2014-04-11 15:00:00',...,'2014-04-15 15:00:00')值('2036548',0,...,4.85) AP PLY BATCH

"BEGIN BATCH USING CONSISTENCY ONE insert into tsmeasures(id,'2014-04-11 15:00:00',...,'2014-04-15 15:00:00') values ('2036548',0,...,4.85) APPLY BATCH"

cql fetch:

cql fetch:


SELECT2014-04-10 16:00:00'..'2014-04-20 17:00:00'FROM tsmeasures WHERE id IN
(2036548,2036479,2036174,650877)

"SELECT '2014-04-10 16:00:00'..'2014-04-20 17:00:00' FROM tsmeasures WHERE id IN (2036548,2036479,2036174,650877)"

因此,2014-04-15 15:00:00被包含在获取的范围内,我可以识别它,因为它是最高的价值。

Thus '2014-04-15 15:00:00' is included in the range of the fetch, and I can identify it because it is the highest value.

我将继续挖掘...

推荐答案

p>这似乎是一个时区问题。看来,您既不存储时也不指定时区,也不会在检索时间戳时指定时区。根据文档 Cassandra应用协调器的时区节点处理写请求,如果客户端没有提供时区。如果时间戳在写入和读取之间发生转换,那可能意味着您的所有或部分Cassandra节点未配置为与客户端相同的时区。

This seems to be a time zone issue. It appears you are neither specifying a timezone when storing nor when retrieving the timestamps. According to the documentation Cassandra applies the timezone of the coordinator node handling the write request if no timezone is supplied by the client. If timestamps shift between writing and reading them, that probably means all or some of your Cassandra nodes are not configured for the same timezone as your client is.

这篇关于Cassandra DB中的日期插入:不平凡的1小时班次问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆