release/86 #2
No files matched your search
@@ -29,6 +29,7 @@ import {
|
||||
AUCTION_DURABILITY_RETRY_QUEUE_KEY,
|
||||
buildAuctionRedisKeys,
|
||||
} from './redis/auction-redis.keys';
|
||||
// [AUCTION-DEBUG] 경매 "중복 멤버" 조사용 임시 계측. 조사 종료 후 제거 대상.
|
||||
import { recordNewRelicCustomEvent } from '../global/observability/new-relic';
|
||||
const AUCTION_DURABILITY_TICK_INTERVAL_MS = 1000;
|
||||
const AUCTION_DURABILITY_BATCH_LIMIT = 20;
|
||||
@@ -168,7 +169,7 @@ export class AuctionDurabilityScheduler
|
||||
}
|
||||
await this.applyDurabilityPayload(payload);
|
||||
applied += 1;
|
||||
// 영속 지연(lag): Redis 커밋 → Mongo 영속까지 걸린 시간 + 이번 배치 백로그.
|
||||
// [AUCTION-DEBUG] 제거 대상. 영속 지연(lag): Redis 커밋 → Mongo 영속까지 걸린 시간 + 배치 백로그.
|
||||
// 사용자가 본 "되돌리기/이력이 2~3 뒤처짐"을 수치화한다(지연이 클수록 undo
|
||||
// 패널이 stale 시퀀스를 보여 엉뚱한 스냅샷 복원 가능성↑).
|
||||
recordNewRelicCustomEvent('AuctionServerDurability', {
|
||||
@@ -426,6 +427,24 @@ export class AuctionDurabilityScheduler
|
||||
payload.afterAuctionMongoProjection,
|
||||
match,
|
||||
);
|
||||
// [AUCTION-DEBUG] 제거 대상. 최종 팀에 같은 유저가 2번 들어갔는지 무조건 검사
|
||||
// (출처가 markSold든 undo 복원이든 projection이든 여기서 결정적으로 잡힌다).
|
||||
const allMemberUserIds = matchTeams.flatMap((team) =>
|
||||
team.members.map((member) => member.userId.toString()),
|
||||
);
|
||||
const distinctMemberCount = new Set(allMemberUserIds).size;
|
||||
recordNewRelicCustomEvent('AuctionServerTeamBuild', {
|
||||
matchId: typeof payload.matchId === 'string' ? payload.matchId : '',
|
||||
auctionStateTransitionId: payload.auctionStateTransitionId,
|
||||
teamCount: matchTeams.length,
|
||||
totalMemberCount: allMemberUserIds.length,
|
||||
distinctMemberCount,
|
||||
hasDuplicateMember: allMemberUserIds.length !== distinctMemberCount,
|
||||
duplicateUserId:
|
||||
allMemberUserIds.find(
|
||||
(id, idx) => allMemberUserIds.indexOf(id) !== idx,
|
||||
) ?? null,
|
||||
});
|
||||
if (matchTeams.length === 0) {
|
||||
throw new Error(
|
||||
`Auction complete side effect produced no match teams for match ${String(payload.matchId)}.`,
|
||||
|
||||
@@ -1017,6 +1017,115 @@ describe('AuctionService', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('keeps Redis sold snapshotBefore isolated from the sold structure mutation', async () => {
|
||||
const matchId = new mongoose.Types.ObjectId();
|
||||
const captainUserId = new mongoose.Types.ObjectId();
|
||||
const playerUserId = new mongoose.Types.ObjectId();
|
||||
const auction = {
|
||||
_id: new mongoose.Types.ObjectId(),
|
||||
auctionEngineVersion: 'redis-v1',
|
||||
matchId,
|
||||
matchSideEffectRevision: 0,
|
||||
};
|
||||
const biddingState = {
|
||||
auctionBidHistory: [],
|
||||
auctionLifecycleId: 'life-1',
|
||||
auctionPlayerOrder: [
|
||||
{
|
||||
userId: playerUserId.toString(),
|
||||
preferredPositions: [{ position: 'MID', priority: 1 }],
|
||||
},
|
||||
],
|
||||
auctionTeams: [
|
||||
{
|
||||
captainUserId: captainUserId.toString(),
|
||||
members: [],
|
||||
remainingBidPointAmount: 1000,
|
||||
teamIndex: 1,
|
||||
},
|
||||
],
|
||||
bidRoundExtensionSeconds: 5,
|
||||
currentAuctionHistorySequence: 3,
|
||||
currentAuctionPlayerOrderIndex: 0,
|
||||
currentAuctionRound: 1,
|
||||
currentBidRoundPlayerUserId: playerUserId.toString(),
|
||||
currentHighestBidPointAmount: 120,
|
||||
currentHighestBidderTeamIndex: 1,
|
||||
initialTeamBidPointAmount: 1000,
|
||||
maximumBidRoundDurationSeconds: 30,
|
||||
passedAuctionPlayerQueue: [],
|
||||
phase: 'bidding',
|
||||
revision: 4,
|
||||
topTierAuctionPriorityThreshold: 'NONE',
|
||||
};
|
||||
const soldState = {
|
||||
...biddingState,
|
||||
auctionTeams: [
|
||||
{
|
||||
...biddingState.auctionTeams[0],
|
||||
members: [
|
||||
{
|
||||
assignedPosition: 'MID',
|
||||
memberAcquisitionBidPointAmount: 120,
|
||||
userId: playerUserId.toString(),
|
||||
},
|
||||
],
|
||||
remainingBidPointAmount: 880,
|
||||
},
|
||||
],
|
||||
currentAuctionHistorySequence: 4,
|
||||
currentHighestBidPointAmount: 120,
|
||||
phase: 'sold',
|
||||
revision: 5,
|
||||
};
|
||||
const {
|
||||
service,
|
||||
auctionRedisCommandService,
|
||||
auctionRedisStateReaderService,
|
||||
} = createService({
|
||||
auction: {
|
||||
findOne: jest.fn().mockResolvedValue(auction),
|
||||
},
|
||||
});
|
||||
auctionRedisStateReaderService.readAuctionStateView
|
||||
.mockResolvedValueOnce(biddingState)
|
||||
.mockResolvedValueOnce(soldState);
|
||||
|
||||
await expect(
|
||||
service.markSold({
|
||||
auctionActionRequestId: '00000000-0000-4000-8000-000000000061',
|
||||
clientObservedAuctionLifecycleId: 'life-1',
|
||||
clientObservedCurrentAuctionPlayerOrderIndex: 0,
|
||||
clientObservedCurrentBidRoundPlayerUserId: playerUserId.toString(),
|
||||
clientObservedPhase: 'bidding',
|
||||
clientObservedRevision: 4,
|
||||
matchId,
|
||||
}),
|
||||
).resolves.toMatchObject({
|
||||
phase: 'sold',
|
||||
revision: 5,
|
||||
});
|
||||
|
||||
const transitionInput =
|
||||
auctionRedisCommandService.applyTransition.mock.calls[0][1];
|
||||
const durabilityPayload = JSON.parse(transitionInput.durabilityPayloadJson);
|
||||
expect(durabilityPayload.snapshotBefore).toMatchObject({
|
||||
phase: 'bidding',
|
||||
revision: 4,
|
||||
});
|
||||
expect(durabilityPayload.snapshotBefore.auctionTeams[0].members).toEqual(
|
||||
[],
|
||||
);
|
||||
expect(
|
||||
durabilityPayload.afterAuctionMongoProjection.auctionTeams[0].members,
|
||||
).toEqual([
|
||||
expect.objectContaining({
|
||||
memberAcquisitionBidPointAmount: 120,
|
||||
userId: playerUserId.toString(),
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
it('returns bid deltas without re-reading the full Redis state', async () => {
|
||||
const matchId = new mongoose.Types.ObjectId();
|
||||
const captainUserId = new mongoose.Types.ObjectId();
|
||||
|
||||
@@ -40,6 +40,7 @@ import {
|
||||
import { AuctionRedisService } from './redis/auction-redis.service';
|
||||
import { AuctionRedisStateReaderService } from './redis/auction-redis-state-reader.service';
|
||||
import { shouldHydrateRedisAuctionState } from './redis/auction-redis.state';
|
||||
// [AUCTION-DEBUG] 경매 "중복 멤버" 조사용 임시 계측. 조사 종료 후 제거 대상.
|
||||
import { recordNewRelicCustomEvent } from '../global/observability/new-relic';
|
||||
|
||||
const AUCTION_MAX_TEAM_SIZE = 5;
|
||||
@@ -910,8 +911,8 @@ export class AuctionService {
|
||||
return this.resolveReplayedRedisActionRequest(matchId, actionRequest);
|
||||
}
|
||||
|
||||
// 중복 멤버 버그 스모킹건: 낙찰 직전, 이 선수가 이미 어느 팀에 들어있는지.
|
||||
// (markRedisSold는 검사 없이 append하므로 true면 그대로 중복이 만들어진다)
|
||||
// [AUCTION-DEBUG] 중복 멤버 버그 스모킹건: 낙찰 직전, 이 선수가 이미 어느 팀에
|
||||
// 들어있는지. (markRedisSold는 검사 없이 append하므로 true면 그대로 중복) — 제거 대상
|
||||
const soldUserId = String(currentPlayer.userId);
|
||||
const existingTeamIndex = structureInput.auctionTeams.find((entry) =>
|
||||
(entry.members ?? []).some(
|
||||
@@ -1699,6 +1700,7 @@ export class AuctionService {
|
||||
(params.auction.matchSideEffectRevision ?? 0) + 1;
|
||||
afterAuctionMongoProjection.matchSideEffectError = undefined;
|
||||
}
|
||||
|
||||
const durabilityPayload = {
|
||||
afterAuctionMongoProjection,
|
||||
auctionActionType: params.action,
|
||||
@@ -1749,7 +1751,7 @@ export class AuctionService {
|
||||
actionRequest: params.actionRequest?.actionRequest,
|
||||
},
|
||||
);
|
||||
// 모든 redis 전환(sold/undo/next/open-bidding/complete)의 백본 타임라인.
|
||||
// [AUCTION-DEBUG] 제거 대상. 모든 redis 전환(sold/undo/next/open-bidding/complete)의 백본 타임라인.
|
||||
// auctionStateTransitionId = `${action}:${lifecycleId}:${auctionActionRequestId}`
|
||||
// 라서 클라의 auctionActionRequestId와 조인된다.
|
||||
recordNewRelicCustomEvent('AuctionServerTransition', {
|
||||
@@ -1884,12 +1886,15 @@ export class AuctionService {
|
||||
0,
|
||||
);
|
||||
|
||||
// undo가 "어느 시점으로" 복원하는지 + 복원된 팀 구성을 기록한다. 라이브 revision과
|
||||
// [AUCTION-DEBUG] 제거 대상. undo가 "어느 시점으로" 복원하는지 + 복원된 팀 구성. 라이브 revision과
|
||||
// 복원 스냅샷 revision의 간격(restoredRevisionLag)이 사용자가 본 "2~3 뒤처짐".
|
||||
// 이 이벤트 직후의 AuctionServerSold가 playerAlreadyInTeam:true면 "undo가 선수를
|
||||
// 안 지운 채 재낙찰 → 중복"이 한 타임라인으로 증명된다.
|
||||
const liveRevisionBeforeUndo = this.numberFromState(state.revision);
|
||||
const restoredRevision = this.numberFromState(params.snapshot.revision);
|
||||
const restoredMemberUserIds = structureInput.auctionTeams.flatMap((entry) =>
|
||||
(entry.members ?? []).map((member) => String(member.userId)),
|
||||
);
|
||||
recordNewRelicCustomEvent('AuctionServerUndo', {
|
||||
matchId,
|
||||
auctionActionRequestId:
|
||||
@@ -1904,10 +1909,9 @@ export class AuctionService {
|
||||
),
|
||||
restoredPhase: phase,
|
||||
restoredOrderIndex: structureInput.currentAuctionPlayerOrderIndex,
|
||||
restoredAssignedMemberCount: structureInput.auctionTeams.reduce(
|
||||
(sum, entry) => sum + (entry.members?.length ?? 0),
|
||||
0,
|
||||
),
|
||||
restoredAssignedMemberCount: restoredMemberUserIds.length,
|
||||
restoredHasDuplicateMember:
|
||||
restoredMemberUserIds.length !== new Set(restoredMemberUserIds).size,
|
||||
undoingCompletedAuction: params.undoingCompletedAuction,
|
||||
});
|
||||
|
||||
@@ -1952,8 +1956,10 @@ export class AuctionService {
|
||||
state: Record<string, unknown>,
|
||||
): Parameters<typeof stringifyAuctionRedisStructureState>[0] {
|
||||
return {
|
||||
auctionPlayerOrder: this.arrayFromState(state.auctionPlayerOrder),
|
||||
auctionTeams: this.arrayFromState(state.auctionTeams),
|
||||
auctionPlayerOrder: this.cloneRedisStructureArray(
|
||||
state.auctionPlayerOrder,
|
||||
),
|
||||
auctionTeams: this.cloneRedisStructureArray(state.auctionTeams),
|
||||
bidRoundExtensionSeconds: this.numberFromState(
|
||||
state.bidRoundExtensionSeconds,
|
||||
5,
|
||||
@@ -1966,14 +1972,14 @@ export class AuctionService {
|
||||
state.initialTeamBidPointAmount,
|
||||
1000,
|
||||
),
|
||||
manualTopTierAuctionPriorityUserIds: this.arrayFromState(
|
||||
manualTopTierAuctionPriorityUserIds: this.cloneRedisStructureArray(
|
||||
state.manualTopTierAuctionPriorityUserIds,
|
||||
),
|
||||
maximumBidRoundDurationSeconds: this.numberFromState(
|
||||
state.maximumBidRoundDurationSeconds,
|
||||
30,
|
||||
),
|
||||
passedAuctionPlayerQueue: this.arrayFromState(
|
||||
passedAuctionPlayerQueue: this.cloneRedisStructureArray(
|
||||
state.passedAuctionPlayerQueue,
|
||||
),
|
||||
topTierAuctionPriorityThreshold: this.isAuctionTopTierThreshold(
|
||||
@@ -1987,14 +1993,15 @@ export class AuctionService {
|
||||
private buildRedisStructureInputFromAuctionSnapshot(
|
||||
snapshot: Record<string, unknown>,
|
||||
): Parameters<typeof stringifyAuctionRedisStructureState>[0] {
|
||||
const legacyTeams = this.arrayFromState(snapshot.teams);
|
||||
const legacyTeams = this.cloneRedisStructureArray(snapshot.teams);
|
||||
const auctionTeams = this.cloneRedisStructureArray(snapshot.auctionTeams);
|
||||
return {
|
||||
auctionPlayerOrder: this.arrayFromState(
|
||||
auctionPlayerOrder: this.cloneRedisStructureArray(
|
||||
snapshot.auctionPlayerOrder ?? snapshot.order,
|
||||
),
|
||||
auctionTeams:
|
||||
this.arrayFromState(snapshot.auctionTeams).length > 0
|
||||
? this.arrayFromState(snapshot.auctionTeams)
|
||||
auctionTeams.length > 0
|
||||
? auctionTeams
|
||||
: convertLegacyAuctionTeamsToRedisTeams(legacyTeams as never),
|
||||
bidRoundExtensionSeconds: this.numberFromState(
|
||||
snapshot.bidRoundExtensionSeconds ?? snapshot.bidExtensionSeconds,
|
||||
@@ -2011,7 +2018,7 @@ export class AuctionService {
|
||||
snapshot.initialTeamBidPointAmount ?? snapshot.initialPoints,
|
||||
1000,
|
||||
),
|
||||
manualTopTierAuctionPriorityUserIds: this.arrayFromState(
|
||||
manualTopTierAuctionPriorityUserIds: this.cloneRedisStructureArray(
|
||||
snapshot.manualTopTierAuctionPriorityUserIds ??
|
||||
snapshot.manualTopTierUserIds,
|
||||
),
|
||||
@@ -2019,7 +2026,7 @@ export class AuctionService {
|
||||
snapshot.maximumBidRoundDurationSeconds ?? snapshot.maxTimerSeconds,
|
||||
30,
|
||||
),
|
||||
passedAuctionPlayerQueue: this.arrayFromState(
|
||||
passedAuctionPlayerQueue: this.cloneRedisStructureArray(
|
||||
snapshot.passedAuctionPlayerQueue ?? snapshot.passedQueue,
|
||||
),
|
||||
topTierAuctionPriorityThreshold: this.isAuctionTopTierThreshold(
|
||||
@@ -2172,6 +2179,13 @@ export class AuctionService {
|
||||
return Array.isArray(value) ? (value as T[]) : [];
|
||||
}
|
||||
|
||||
private cloneRedisStructureArray<T = never>(value: unknown): T[] {
|
||||
// 구조 전환 핸들러가 이 작업본을 변이하므로 snapshotBefore 원본과 참조를 공유하면 안 된다.
|
||||
// structuredClone은 ObjectId를 [object Object]로 망가뜨리므로, 코드베이스 관행대로
|
||||
// JSON 클론으로 깊은 복사 + ObjectId/Date 정규화를 함께 수행한다.
|
||||
return JSON.parse(JSON.stringify(this.arrayFromState<T>(value))) as T[];
|
||||
}
|
||||
|
||||
private numberFromState(value: unknown, fallback = 0): number {
|
||||
const parsed = Number(value);
|
||||
return Number.isFinite(parsed) ? parsed : fallback;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// [AUCTION-DEBUG] 경매 "중복 멤버" 조사용 서버 계측 래퍼. 조사 종료 후 호출부와 함께
|
||||
// 제거 대상(범용으로 남길 거면 이 마커만 떼면 됨).
|
||||
import newrelicAgent from 'newrelic';
|
||||
|
||||
export type NewRelicAttributeValue = string | number | boolean | null;
|
||||
|
||||
@@ -8,6 +8,8 @@ import {
|
||||
resolveAuctionErrorMessage,
|
||||
resolveAuctionRejectionMessage,
|
||||
} from './auctionRejectionMessages';
|
||||
// [AUCTION-DEBUG] 경매 "중복 멤버" 조사용 임시 계측. 조사 종료 후 제거 대상
|
||||
// (호출부는 전부 addNewRelicPageAction / describeAuctionForTelemetry 로 grep 가능).
|
||||
import { addNewRelicPageAction } from '../lib/observability/new-relic';
|
||||
|
||||
type ConnectionStatus =
|
||||
@@ -859,6 +861,7 @@ function resolveCurrentBidPointAmount(auction: ApiAuction): number {
|
||||
return Number.isFinite(bidPointAmount) ? bidPointAmount : 0;
|
||||
}
|
||||
|
||||
// [AUCTION-DEBUG] 아래 텔레메트리 헬퍼들과 호출부는 조사 종료 후 제거 대상.
|
||||
type AuctionTelemetryAttributes = Record<string, string | number | boolean | null>;
|
||||
|
||||
function readAuctionHistorySequence(auction: ApiAuction | null | undefined) {
|
||||
|
||||
Reference in new issue
Block a user