Skip to content

Commit

Permalink
Merge pull request #421 from ase-101/release-1.1.0
Browse files Browse the repository at this point in the history
ES-842 slot removal issue fixed
  • Loading branch information
ckm007 authored Nov 9, 2024
2 parents dad3ebb + 53cbe72 commit 4935d62
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import org.springframework.data.redis.connection.ReturnType;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.nio.charset.StandardCharsets;
import java.util.Locale;

import static io.mosip.signup.util.SignUpConstants.*;
Expand All @@ -47,8 +49,17 @@ public class CacheUtilService {



private static final String CLEANUP_SCRIPT = "local hash_name = KEYS[1]\n" +
"local current_time = tonumber(ARGV[1])\n" +
private static final String CLEANUP_SCRIPT = "local function binary_to_long(binary_str)\n" +
" local result = 0\n" +
" for i = 1, #binary_str do\n" +
" result = result * 256 + binary_str:byte(i)\n" +
" end\n" +
" return result\n" +
"end" +
"\n" +
"local hash_name = KEYS[1]\n" +
"local time = redis.call(\"TIME\")\n" +
"local current_time = ( tonumber(time[1]) * 1000) + math.floor( tonumber(time[2]) / 1000)\n" +
"local verified_slot_cache_keys = {}\n" +
"local fields_to_delete = {}\n" +
"local delcount=0\n" +
Expand All @@ -59,8 +70,8 @@ public class CacheUtilService {
" local hash_data = result[2]\n" +
" for i = 1, #hash_data, 2 do\n" +
" local field = hash_data[i]\n" +
" local value = tonumber(hash_data[i + 1])\n" +
" if value and value < current_time then\n" +
" local value = binary_to_long(hash_data[i + 1])\n" +
" if value < current_time then\n" +
" local separator_index = string.find(field, \"###\")\n" +
" if separator_index then \n" +
" local key_part = string.sub(field, 1, separator_index - 1)\n" +
Expand Down Expand Up @@ -270,16 +281,14 @@ public void clearExpiredSlots() {
scriptHash = redisConnectionFactory.getConnection().scriptingCommands().scriptLoad(CLEANUP_SCRIPT.getBytes());
}
LockAssert.assertLocked();
Long currentTimeMillis = System.currentTimeMillis(); // Current time in millis
log.info("Running scheduled cleanup task - task to clear expired slots with script hash: {} {}", scriptHash,
SLOTS_CONNECTED);

int keysDeleted = redisConnectionFactory.getConnection().scriptingCommands().evalSha(
long keysDeleted = redisConnectionFactory.getConnection().scriptingCommands().evalSha(
scriptHash,
ReturnType.INTEGER,
1, // Number of keys
SLOTS_CONNECTED.getBytes(), // The Redis hash name (key)
Longs.toByteArray(currentTimeMillis) // Current time in milliseconds
SLOTS_CONNECTED.getBytes() // The Redis hash name (key)
);
log.info("Running scheduled cleanup task - Keys Deleted count: {}", keysDeleted);
}
Expand All @@ -297,10 +306,10 @@ public Long getSetSlotCount(String field, long expireTimeInMillis, Integer maxCo
addSlotScriptHash,
ReturnType.INTEGER,
1, // Number of keys (SLOTS_CONNECTED is the key here)
SLOTS_CONNECTED.getBytes(), // key (first argument in Lua script)
field.getBytes(), // field (second argument in Lua script)
Longs.toByteArray(expireTimeInMillis), // value (third argument in Lua script)
String.valueOf(maxCount).getBytes() // maxCount (fourth argument, should be passed as a string)
SLOTS_CONNECTED.getBytes(StandardCharsets.UTF_8), // key (first argument in Lua script)
field.getBytes(StandardCharsets.UTF_8), // field (second argument in Lua script)
String.valueOf(expireTimeInMillis).getBytes(StandardCharsets.UTF_8), // value
String.valueOf(maxCount).getBytes(StandardCharsets.UTF_8) // maxCount
);
}
return -1L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ mosip.signup.slot.expire-in-seconds=1200

## cron trigger to run the expired slots cleanup script from the "slots_connected" cache. As the slot expire is set to 20
# minutes configuring the cleanup script to run every 20 minutes once
mosip.signup.slot.cleanup-cron=0 0/20 * * * *
mosip.signup.slot.cleanup-cron=0/20 * * * * *

## Time(in seconds) allowed to get slot after the authorization code exchange.
mosip.signup.identity-verification.txn.timeout=180
Expand Down Expand Up @@ -110,7 +110,6 @@ mosip.esignet.cache.size={'challenge_generated': 200, \
'identity_verifiers' : 20, \
'idv_metadata' : 30,\
'slot_allotted' : 200, \
'slots_connected': 200,\
'verified_slot' : 200 }

## Note: keystore TTL should be more than the key_alias cache TTL.
Expand All @@ -126,7 +125,6 @@ mosip.esignet.cache.expire-in-seconds={'challenge_generated': ${mosip.signup.una
'identity_verifiers' : 800, \
'idv_metadata' : 500,\
'slot_allotted' : ${mosip.signup.slot-allotted.timeout}, \
'slots_connected': 1000,\
'verified_slot' : ${mosip.signup.verified-slot.timeout} }

## ------------------------------------- Auth adapter ------------------------------------------------------------------
Expand Down

0 comments on commit 4935d62

Please sign in to comment.