0

I am trying to use the flake id instead of sequence in the database so that I can use the write-behind persistence mechanism. However I am getting this weird error where when I return the id as json the id changes but from postman it is fine.

Cache Code

long newId = hazelcastInstance.getFlakeIdGenerator("pk").newId();
meta.setId(newId);
getMetaCache().set(meta.getId(), meta);

Controller code

WorkflowMeta workflowMeta = objectMapper.readValue(request.getInputStream(), WorkflowMeta.class);
workflowService.saveWorkflowMeta(workflowMeta);

URI getUrl = HttpUtil.getRetrieveUrlForPostResponse(request, "/rest/priv/workflow/getWorkflowMetaById/" + workflowMeta.getId());
return ResponseEntity.created(getUrl).body("{\"success\":true, \"id\":" + workflowMeta.getId() + ", \"sucks\":true}");

For some weird reason, network->preview tab on chrome shows this:
{success: true, id: 115504597384036350, sucks: true}
network->preview tab

network->response tab on chrome shows this:
{"success":true, "id":115505723818901505, "sucks":true}
network->response tab

My UI code unfortunately picks up the previewed tab data which is wrong. Has anyone encountered this issue before or happens to know how to fix it?

Pilo
  • 15
  • 3
  • It looks like you are calling `hazelcastInstance.getFlakeIdGenerator("pk").newId()` for each request. Can you please check it on your code? – Alparslan Avci Nov 15 '18 at 20:28
  • Yes I like to code incrementally, my first usecase is to insert then I will work on update. Later I will check if id exists, if not then get newId. I don't believe it is related to the issue I have though. Even first call don't work. – Pilo Nov 15 '18 at 20:57
  • What is the error? – wildnez Nov 16 '18 at 07:19
  • As @wildnez stated, can you please explain your expected behavior in detail? – Alparslan Avci Nov 16 '18 at 12:34
  • When I call getFlakeIdGenerator("pk").newId(), it returns 115505723818901505 but when I return it back to client, the response somehow gives 115504597384036350 instead. It's as if id is called again or something when i return but I don't. – Pilo Nov 16 '18 at 15:12
  • I just added 2 screen shot to show it, ids are different but you can see preview tab and response tab shows different numbers. The UI code unfortunately picks up the wrong number from the data shown in preview tab. – Pilo Nov 16 '18 at 15:22
  • I just figured it out, it is a limitation on javascript. Numbers can only go up to 54 bits rather than 64 so it can't be represented. Sry for the fuss and thanks for checking. – Pilo Nov 16 '18 at 15:56

0 Answers0