Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

I want to set the Cassandra timezone to UTC + 9 or KST. #130

Closed
jakim9913 opened this issue Apr 18, 2022 · 15 comments
Closed

I want to set the Cassandra timezone to UTC + 9 or KST. #130

jakim9913 opened this issue Apr 18, 2022 · 15 comments
Assignees

Comments

@jakim9913
Copy link

I am using Cassandra 3.11.7 with spring boot.
I want to set KST time which is UTC + 9 in Cassandra time zone.
So I'm looking for a way to set the Cassandra timezone.

What should I do?
thank you.

@nosan
Copy link
Owner

nosan commented Apr 18, 2022

You can add cassandra.embedded.system-properties[user.timezone]=Asia/Seoul to your application.properties

@nosan
Copy link
Owner

nosan commented Apr 18, 2022

Or you can do:

@Bean
public CassandraBuilderConfigurator timezoneConfigurator(){
     return builder -> builder.addSystemProperty("user.timezone","Asia/Seoul");
}

@jakim9913
Copy link
Author

Thanks for the reply
However, the code does not work and I get an error.

I don't have CassandraBuilderConfigurator.
image

What is CassandraBuilderConfigurator?

I used public class CassandraConfig extends AbstractReactiveCassandraConfiguration {}

I tried converting the local time as follows, but it doesn't work

@Bean
    public CassandraCustomConversions customConversions() {
        List<Converter<?, ?>> converters = new ArrayList<>();
        Set<Converter<?, ?>> converters2 = new HashSet<>();
        converters.add(new MyCustomConverter());

        return new CassandraCustomConversions(converters);
    }
    @ReadingConverter
    public class MyCustomConverter implements Converter<Instant, LocalDateTime> {
        @Override public LocalDateTime convert(Instant instant) { // 여기에서 필요한 변경사항을 적용하면 됩니다.
           // return LocalDateTime.ofInstant(instant, ZoneOffset.of("+09:00"));
            return ZonedDateTime.now(ZoneId.of("Asia/Seoul")).toLocalDateTime();

        }
    }

It's a web application, so it shouldn't affect time settings in other parts.

Isn't there a better way?

thank you

@nosan
Copy link
Owner

nosan commented Apr 19, 2022

What version do you use? (Cassandra spring boot starter)

Have tried application properties?

@jakim9913
Copy link
Author

I am using embedded Cassandra 3.11.7 with spring boot.

 <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-cassandra</artifactId>
            <version>2.2.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.github.nosan</groupId>
            <artifactId>embedded-cassandra-spring-boot-starter</artifactId>
            <version>2.0.5</version>

I have application propertise.

#Update Property File
#Tue Jan 19 09:46:34 KST 2021
cassandra.password=cassandra
cassandra.username=cassandra
cassandra.keyspace=manage
cassandra.ip=127.0.0.1
cassandra.port=9042
cassandra.jvm.xms=2g
cassandra.jvm.xmx=4g

@nosan
Copy link
Owner

nosan commented Apr 19, 2022

Now it is clear :)

application.properties:

com.github.nosan.embedded.cassandra.system-properties[user.timezone]=Asia/Seoul

or


@Bean
public CassandraFactoryCustomizer<EmbeddedCassandraFactory> timezoneCustomizer(){
    return cassandraFactory -> cassandraFactory.getSystemProperties().put("user.timezone","Asia/Seoul");
}

@jakim9913
Copy link
Author

thank for the reply.

However, it does not apply.

Here's what's applied:

  1. cassandra propertise
    cassandra.timezone=Asia/Seoul
  2. cassandra config
    @Value("${cassandra.timezone}") private String timezone;
  3. timezoneCustomizer method add
    @Bean public CassandraFactoryCustomizer<EmbeddedCassandraFactory> timezoneCustomizer(){ return cassandraFactory -> cassandraFactory.getSystemProperties().put("cassandra.timezone", timezone); }
  4. inser data - create time check

current time : 2022-04-19 17:20:35
DB insert time : 2022-04-19 08:15:35

There is still a 9 hour difference.

@nosan
Copy link
Owner

nosan commented Apr 19, 2022

Why cassandra.timezone? Where did you get this?

@jakim9913
Copy link
Author

I have cassadra.config

cassandra.username=
cassandra.keyspace=manage
cassandra.ip=127.0.0.1
cassandra.port=9042
cassandra.jvm.xms=2g
cassandra.jvm.xmx=4g```

@nosan
Copy link
Owner

nosan commented Apr 19, 2022

@Value("${cassandra.timezone}") private String timezone;

    @Bean
    public CassandraFactoryCustomizer<EmbeddedCassandraFactory> timezoneCustomizer() {
        return cassandraFactory -> cassandraFactory.getSystemProperties().put("user.timezone", timezone);
    }

@jakim9913
Copy link
Author

The insert time and the current time are still different.

Is it forced to change to utc timezone when inserted in cassandra?

@nosan
Copy link
Owner

nosan commented Apr 19, 2022

user.timezone Java system property explicitly set a default time zone for Apache Cassandra.
How actually Cassandra treats this property I don't know, it is better to ask Cassandra's team.

@nosan
Copy link
Owner

nosan commented Apr 19, 2022

I believe your question is not related to Embedded Cassandra. Looks like you have a general issue with how to work date-time values in Apache Cassandra.

@jakim9913
Copy link
Author

thank you for your reply

If you know the Apache Cassandra official contact github address or Q&A site address, please share.

@nosan
Copy link
Owner

nosan commented Apr 22, 2022

@nosan nosan closed this as completed Apr 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants