fix: harden result polling and Redis 8.10 operations
Preserve tournament result jobs through lock contention and transient failures, atomically schedule retries before acknowledgement, and publish initial polls after releasing the preparation lock. Fix Redis connection blocking, durability Hash cleanup, duplicate auction request ordering, and scheduled-job promotion. Use native Redis 8.10 stream, lock, counter, and field-expiring cache operations with invalidation fencing. Repair 90 test type errors and add a repeatable API typecheck command. Validation: 704 API tests, 129 web tests, 31 real Redis integration tests, 3 dependency checks, workspace type checks and builds, and changed-file lint.
This commit is contained in:
1 parent
0c4c4239ec
commit
4b8ccf0077
49 files changed
+2214
-371
No files matched your search
@@ -2103,7 +2103,7 @@ describe('AuctionService', () => {
|
||||
});
|
||||
|
||||
expect(auction.currentBid).toBe(970);
|
||||
expect(auction.currentBidderTeamIndex).toBe(1);
|
||||
expect(auction).toHaveProperty('currentBidderTeamIndex', 1);
|
||||
expect(auction.bids).toEqual([
|
||||
expect.objectContaining({
|
||||
teamIndex: 1,
|
||||
@@ -2397,7 +2397,7 @@ describe('AuctionService', () => {
|
||||
await service.next(matchId);
|
||||
|
||||
expect(auction.phase).toBe('complete');
|
||||
expect(auction.completedAt).toBeInstanceOf(Date);
|
||||
expect(auction).toHaveProperty('completedAt', expect.any(Date));
|
||||
expect(auction.save).toHaveBeenCalledTimes(1);
|
||||
expect(match.save).toHaveBeenCalledTimes(2);
|
||||
expect(match.teams).toEqual([
|
||||
|
||||
@@ -39,6 +39,7 @@ import {
|
||||
stringifyAuctionRedisStructureState,
|
||||
} from './redis/auction-redis-projection';
|
||||
import { AuctionRedisService } from './redis/auction-redis.service';
|
||||
import { AUCTION_CLEANUP_DURABILITY_SCRIPT } from './redis/auction-redis.cleanup';
|
||||
import { AuctionRedisStateReaderService } from './redis/auction-redis-state-reader.service';
|
||||
import { shouldHydrateRedisAuctionState } from './redis/auction-redis.state';
|
||||
// [AUCTION-DEBUG] 경매 "중복 멤버" 조사용 임시 계측. 조사 종료 후 제거 대상.
|
||||
@@ -2970,54 +2971,16 @@ export class AuctionService {
|
||||
const payloadKeys = Array.isArray(reply[1]) ? reply[1].map(String) : [];
|
||||
if (payloadKeys.length === 0) continue;
|
||||
|
||||
const values = await this.auctionRedisService
|
||||
.raw()
|
||||
.sendCommand(['MGET', ...payloadKeys]);
|
||||
const payloadKeysToDelete = payloadKeys.filter((payloadKey, index) =>
|
||||
this.shouldDeleteRedisDurabilityPayload(
|
||||
Array.isArray(values) ? values[index] : undefined,
|
||||
expectedAuctionLifecycleId,
|
||||
payloadKey,
|
||||
),
|
||||
);
|
||||
if (payloadKeysToDelete.length === 0) continue;
|
||||
|
||||
await this.auctionRedisService
|
||||
.raw()
|
||||
.sendCommand([
|
||||
'ZREM',
|
||||
await this.auctionRedisService.evalScript(
|
||||
AUCTION_CLEANUP_DURABILITY_SCRIPT,
|
||||
[
|
||||
keys.durabilityRetryQueueKey,
|
||||
...payloadKeysToDelete,
|
||||
]);
|
||||
await this.auctionRedisService
|
||||
.raw()
|
||||
.sendCommand([
|
||||
'ZREM',
|
||||
keys.durabilityDeadLetterQueueKey,
|
||||
...payloadKeysToDelete,
|
||||
]);
|
||||
await this.auctionRedisService
|
||||
.raw()
|
||||
.sendCommand(['DEL', ...payloadKeysToDelete]);
|
||||
} while (cursor !== '0');
|
||||
}
|
||||
|
||||
private shouldDeleteRedisDurabilityPayload(
|
||||
payloadValue: unknown,
|
||||
expectedAuctionLifecycleId: string | undefined,
|
||||
payloadKey: string,
|
||||
): boolean {
|
||||
if (!expectedAuctionLifecycleId) return true;
|
||||
if (typeof payloadValue !== 'string') return false;
|
||||
try {
|
||||
const payload = JSON.parse(payloadValue) as Record<string, unknown>;
|
||||
return payload.auctionLifecycleId === expectedAuctionLifecycleId;
|
||||
} catch {
|
||||
this.logger.warn(
|
||||
`Failed to parse auction durability payload ${payloadKey}.`,
|
||||
...payloadKeys,
|
||||
],
|
||||
[expectedAuctionLifecycleId ?? ''],
|
||||
);
|
||||
return false;
|
||||
}
|
||||
} while (cursor !== '0');
|
||||
}
|
||||
|
||||
private enqueueBackgroundOrderEnrichment(params: {
|
||||
|
||||
@@ -317,7 +317,7 @@ if actionRequestScopeKey ~= '' then
|
||||
actionRequestPrefix .. 'responseServerTimestampMS',
|
||||
tostring(currentRedisTimestampMS)
|
||||
)
|
||||
redis.call('RPUSH', auctionActionRequestResultOrderKey, actionRequestScopeKey)
|
||||
-- The reservation already inserted this request into the order list.
|
||||
end
|
||||
|
||||
return {'OK', auctionStateTransitionId, tostring(newRevision), tostring(currentRedisTimestampMS)}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import { defineAuctionRedisScript } from './auction-redis.scripts';
|
||||
|
||||
// Compare the lifecycle and remove the payload and its indexes atomically.
|
||||
export const AUCTION_CLEANUP_DURABILITY_SCRIPT = defineAuctionRedisScript(
|
||||
'auction.cleanupDurability',
|
||||
`
|
||||
local deleted = 0
|
||||
for i = 3, #KEYS do
|
||||
local key = KEYS[i]
|
||||
local keyType = redis.call('TYPE', key).ok
|
||||
local matches = ARGV[1] == ''
|
||||
if not matches and keyType == 'hash' then
|
||||
matches = redis.call('HGET', key, 'auctionLifecycleId') == ARGV[1]
|
||||
elseif not matches and keyType == 'string' then
|
||||
-- Retain compatibility with payloads written before the Hash format.
|
||||
local ok, payload = pcall(cjson.decode, redis.call('GET', key))
|
||||
matches = ok and type(payload) == 'table' and payload.auctionLifecycleId == ARGV[1]
|
||||
end
|
||||
if matches then
|
||||
redis.call('ZREM', KEYS[1], key)
|
||||
redis.call('ZREM', KEYS[2], key)
|
||||
deleted = deleted + redis.call('UNLINK', key)
|
||||
end
|
||||
end
|
||||
return deleted
|
||||
`,
|
||||
);
|
||||
@@ -129,13 +129,7 @@ export class AuctionRedisService implements OnModuleDestroy {
|
||||
}
|
||||
|
||||
public async releaseTokenLock(key: string, token: string): Promise<boolean> {
|
||||
const result = await this.client.sendCommand([
|
||||
'EVAL',
|
||||
'if redis.call("GET", KEYS[1]) == ARGV[1] then return redis.call("DEL", KEYS[1]) else return 0 end',
|
||||
'1',
|
||||
key,
|
||||
token,
|
||||
]);
|
||||
const result = await this.client.sendCommand(['DELEX', key, 'IFEQ', token]);
|
||||
return Number(result) === 1;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user