Skip to content

Expiry of document not working at all? [DATACOUCH-630] #941

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Oct 8, 2020 · 8 comments
Closed
Assignees
Labels
in: mapping Mapping and conversion infrastructure type: bug A general bug

Comments

@spring-projects-issues
Copy link

David Prevost opened DATACOUCH-630 and commented

While trying to test if the expiry of my document was set correctly, I find out that it is not set at all.

Basically, I did a IT that create, and update my entity having @Document(expiry = 60) and then I use the couchbase api to validate the expiry and it is never set.

The output of my test below show that the expiry date is alway 1970-01-01 unless I use the getAndTouch API of couchbase

Expiry on create using JPA save
Optional[1970-01-01T00:00:00Z]
Expiry on update using JPA save
Optional[1970-01-01T00:00:00Z]
Expiry on getAndTouch of couchbase API
Optional[2020-10-08T14:34:43Z]

 

Also, if we analyze occurences of CouchbaseDocument#getExpiration then it does not seems to be use anywhere with the couchbase api. And if we check CouchbaseDocument#export, the expiry is not in the content (not sure if it can actually be part of the content....)

 

    @Test
    public void givenSavedUserSession_whenUpdate_thenExpiryIsAlsoUpdated(
        @Autowired final CouchbaseClientFactory couchbaseClient) {

        final Collection operations = couchbaseClient.getBucket().defaultCollection();

        final UUID userUuid = UUID.randomUUID();
        final String id = userUuid.toString();
        final UserSessionEntity userSessionEntity =
            UserSessionEntityBuilder.builder().userUuid(userUuid).jtwTokenIds(Set.of(UUID.randomUUID())).build();
        userSessionDao.save(userSessionEntity);

        final GetResult resultWithExpiry =
            operations.get(id, GetOptions.getOptions().project("jtwTokenIds").withExpiry(true));

        System.out.println("Expiry on create using JPA save");
        System.out.println(resultWithExpiry.expiryTime());

        // Wait 5 sec to better compare create expiry and update expiry
        userSessionDao.save(userSessionEntity);

        final GetResult resultWithExpiry2 =
            operations.get(id, GetOptions.getOptions().project("jtwTokenIds").withExpiry(true));

        System.out.println("Expiry on update using JPA save");
        System.out.println(resultWithExpiry2.expiryTime());

        operations.getAndTouch(id, Duration.ofSeconds(60));

        final GetResult resultWithExpiry3 =
            operations.get(id, GetOptions.getOptions().project("jtwTokenIds").withExpiry(true));

        System.out.println("Expiry on getAndTouch of couchbase API");
        System.out.println(resultWithExpiry3.expiryTime());
    }



@Document(expiry = 60)
public class UserSessionEntity {    
    @Id
    private UUID userUuid;    
    @Version
    private long version;

    @Field
    @NotNull
    private Set<UUID> jtwTokenIds;
}

public interface UserSessionDao
    extends CrudRepository<UserSessionEntity, UUID> {
}

 

 

 


Affects: 4.0.4 (Neumann SR4)

Referenced from: pull request #285

Backported to: 4.1.3 (2020.0.3), 4.0.7 (Neumann SR7)

@spring-projects-issues
Copy link
Author

David Prevost commented

Maybe already fix with DATACOUCH-622

@spring-projects-issues
Copy link
Author

David Prevost commented

Or maybe more by https://jira.spring.io/browse/DATACOUCH-605

@spring-projects-issues
Copy link
Author

David Prevost commented

Mmm finally, it seem to be more DATACOUCH-608

@spring-projects-issues
Copy link
Author

Michael Reiche commented

-fixed in datacouch-623-

@spring-projects-issues
Copy link
Author

David Prevost commented

Michael Reiche datacouch-623 is about CAS which is not the same thing as expiry....

@spring-projects-issues
Copy link
Author

Michael Reiche commented

datacouch-608 or 616.

 

In src/main/java/org/springframework/data/couchbase/core/ReactiveInsertByIdOperationSupport.java:

@@ -98,7 +97,7 @@ private InsertOptions buildInsertOptions() {

} else if (durabilityLevel != DurabilityLevel.NONE) {

options.durability(durabilityLevel); }

  • if (expiry != null) {
  • if (expiry != null && ! expiry.isZero()) {

@spring-projects-issues
Copy link
Author

Michael Reiche commented

The example given shows an entity created from scratch without a CAS.  It will not demonstrate the issue described below.

repository.save() uses either UpsertById() or ReplaceById().

if (hasNonZeroVersionProperty(entity, operations.getConverter())) {
 return (Mono<S>) operations.replaceById(entityInformation.getJavaType()).one(entity);
} else {
 return (Mono<S>) operations.upsertById(entityInformation.getJavaType()).one(entity);
}

ReplaceById() is missing the handling of expiry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: mapping Mapping and conversion infrastructure type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants