| Rev |
Age |
Author |
Path |
Log message |
Diff |
| 36375 |
1 h 47 m |
amit |
/trunk/profitmandi-dao/src/main/java/com/spice/profitmandi/service/transaction/ |
Added Rising Star/NEW |
|
| 36374 |
2 h 0 m |
ranu |
/trunk/ |
schemes and offer for v2 version |
|
| 36372 |
4 h 37 m |
amit |
/trunk/profitmandi-dao/src/main/java/com/spice/profitmandi/ |
Wallet: SELECT FOR UPDATE on user_wallet mutations to close lost-update hole
addAmountToWallet/consumeAmountFromWallet(x2)/rollbackAmountFromWallet all
follow a read-modify-write pattern on user_wallet with no pessimistic lock
and no @Version, so two concurrent tx for the same partner both read the
same pre-snapshot amount, compute their own deltas, and commit - the second
UPDATE silently overwrites the first's credit/debit. user_wallet_history
still gets both rows, so balance drifts vs sum(history) with no exception.
Replaces the misnamed (and body-broken) selectByIdForUpdate - whose
implementation was a plain selectById, not a lock - with a new
selectByRetailerIdForUpdate that issues SELECT ... FOR UPDATE via
LockModeType.PESSIMISTIC_WRITE, mirroring the idiom already used in
GenericRepositoryImpl.selectByIdForUpdate and OrderRepositoryImpl.
Preserves the create-on-missing behavior of selectByRetailerId so
first-time partners keep working.
Switches the four read-modify-write call sites in WalletServiceImpl from
selectByRetailerId to the new locking variant. Read-only callers
(getUserWalletByUserId, getUserWalletHistoryByUserId, etc.) keep using
the non-locking selectByRetailerId - MVCC snapshot reads stay non-blocking
for display/statement endpoints.
Also drops the stale commented-out selectByIdForUpdate line in
rollbackAmountFromWallet and removes the broken method from the
UserWalletRepository interface / impl - it had zero live callers.
Blast radius: every write call to these three wallet methods now holds
an X-lock on the target user_wallet row for the rest of the outer tx.
Concurrent write tx for the same partner will briefly serialize at the
SELECT FOR UPDATE - correct serialization instead of silent drift.
Read-only traffic is unaffected (MVCC). |
|
| 36371 |
5 h 13 m |
amit |
/trunk/ |
HDFC webhook: INSERT IGNORE on hdfc_payment to fix concurrent-duplicate 500 storm
Replaces persist() with a native INSERT IGNORE so concurrent same-UTR webhook
retries serialize on the unique-index check, and the loser gets a 0-row no-op
(warning, not exception). Outer @Transactional session stays clean, Spring
commits normally, HDFC sees 200 on both the winner (Success) and the loser
(Duplicate) - retry amplification ends.
Flow:
persist(hdfcPayment) -> insertIgnore(hdfcPayment) + selectByUtrNo(utr)
- inserted == 1: proceed with wallet / sidbi side-effects using fetched id
- inserted == 0: respond Duplicate, skip side-effects (owned by winning tx)
- defensive: log warn if insertIgnore returned 0 but selectByUtrNo finds
no row (could mean IGNORE swallowed a non-duplicate issue like truncation)
Also drops HdfcProcessingHelper (r36366) which used REQUIRES_NEW for the same
goal; that approach required a second JDBC connection and is no longer needed
with SQL-level idempotency.
Does NOT touch the wallet-side lost-update hole (user_wallet read-modify-write
without FOR UPDATE). That is a separate commit. |
|
| 36366 |
1 d 0 h |
amit |
/trunk/profitmandi-dao/src/main/java/com/spice/profitmandi/service/transaction/ |
Add HdfcProcessingHelper: per-payment REQUIRES_NEW wrapper for HDFC credit writes
Isolates the hdfc_payment insert + wallet-credit / sidbi-sanction writes in
their own transaction so concurrent duplicate webhooks (HDFC retry, manual
entry, reconciliation) can't poison the caller's session. On the deadlock/
duplicate-key path (DataIntegrityViolationException), logs once at INFO and
returns silently — the row's side-effects are owned by whichever path
inserted it first; re-applying would double-credit.
Mirrors the OfferProcessingHelper pattern (also REQUIRES_NEW per item),
keeping the controller's outer transaction clean and making this method
safe to invoke from a batch loop later without refactor. |
|
| 36362 |
1 d 21 h |
amit |
/trunk/profitmandi-dao/src/main/ |
Make fofo_order creation idempotent on (fofo_id, invoice_number)
Fixes insert-intention gap-lock deadlocks on idx_invoice_number observed in
SHOW ENGINE INNODB STATUS at 2026-04-22 13:01:54 — two concurrent requests
inserting the same invoice_number for the same customer (client retry /
upstream webhook retry pattern).
- OrderServiceImpl.createAndGetFofoOrder: select-then-insert idempotency.
Fast path returns existing row if already created; slow-race path catches
DataIntegrityViolationException and re-selects the winner's row.
- add_uk_fofo_order_fofo_invoice.sql: adds UNIQUE KEY (fofo_id, invoice_number)
so the loser of a concurrent-insert race gets a clean DIVE instead of a
silent duplicate row (pre-check showed zero existing dup groups, safe).
findExistingFofoOrder wraps the repo call to swallow the repo's declared
ProfitMandiBusinessException — the impl actually returns null on not-found
(constructs an exception but never throws), so the swallow matches reality. |
|
| 36359 |
1 d 22 h |
ranu |
/trunk/profitmandi-dao/src/main/java/com/spice/profitmandi/service/ |
rbm rating dashboard view commited |
|
| 36357 |
1 d 23 h |
amit |
/trunk/profitmandi-dao/src/main/java/com/spice/profitmandi/service/ |
Fix background-thread 'no session' error in DB guard. CronBatchRepository.selectRunningForOffer uses getCurrentSession() which needs an open tx; when OfferBatchService.processOfferWithBatch is called from the async worker thread (no outer tx), the guard query crashed with 'Could not obtain transaction-synchronized Session'. Offer 8819 submit succeeded but the background run died at the guard — before createBatch, so no cron_batch / cron_batch_item rows. Added CronBatchService.findRunningForOffer wrapping the repo call in @Transactional(readOnly=true); orchestrator calls the service method instead of repo directly. Matches the pattern used by loadOfferRequest / createBatch / calculate*Payouts — every caller opens its own tx. |
|
| 36355 |
2 d 0 h |
amit |
/trunk/profitmandi-dao/src/main/java/com/spice/profitmandi/service/offers/ |
Skip already-paid partners before creating cron_batch_item rows. Adds hasRemainingSellinPayout / hasRemainingOfferPayout predicates on OfferProcessingHelper that mirror the amount calc in processPartner*Payout. Orchestrator filters partnerPayouts through these before createBatch — partners whose serials are fully paid (amount=0 after subtracting serialNumberPaid) are excluded entirely. Reruns of a completed offer now create no batch at all (log says 'all N eligible partners already fully paid, skipping batch'); partial reruns log filtered count. Avoids audit-trail noise of SUCCESS items that did zero work. |
|
| 36354 |
2 d 1 h |
amit |
/trunk/profitmandi-dao/src/main/java/com/spice/profitmandi/ |
DB-backed concurrent-run guard for OfferBatchService.processOfferWithBatch. Adds CronBatchRepository.selectRunningForOffer(offerId) — single HQL query for RUNNING cron_batch rows named processSellinOffer-N or processActivationOffer-N. OfferBatchService early-returns (with a log) if any such row exists. Covers the three gaps the in-memory guard can't: JVM restart, multi-JVM, cron CLI + user click racing. Applies to both sync (cron --processOffersWithBatch) and async (/offer/process HTTP) paths. |
|
| 36350 |
2 d 2 h |
aman |
/trunk/profitmandi-dao/src/main/java/com/spice/profitmandi/service/user/ |
Fix:Add brand commitment, ASM details, and finance option in WOD initiation email |
|
| 36347 |
2 d 2 h |
amit |
/trunk/profitmandi-dao/src/main/java/com/spice/profitmandi/service/offers/ |
Add submitBatchAsync for fire-and-forget /offer/process — schedules processOfferWithBatch on a bounded background pool (3 daemon threads) and returns immediately with a human-readable message. In-memory ConcurrentHashMap.newKeySet() per-offerId guard prevents duplicate concurrent runs for the same offer (the scenario that caused offer 8802 deadlocks). Sync processOfferWithBatch kept unchanged for cron CLI (--processOffersWithBatch). |
|
| 36342 |
2 d 4 h |
amit |
/trunk/profitmandi-dao/src/main/java/com/spice/profitmandi/service/offers/ |
Add OfferBatchService orchestrator — shared batch entrypoint for offer processing, used by cron CLI and /offer/process controllers. Loads offer, calls calculate*Payouts (read), creates cron_batch, runs each partner in REQUIRES_NEW via OfferProcessingHelper, finalizes batch and emails on partial failure. No @Transactional on the class — must not carry outer tx. |
|
| 36337 |
2 d 5 h |
amit |
/trunk/profitmandi-dao/src/main/java/com/spice/profitmandi/service/ |
Move CronBatchService and OfferProcessingHelper from cron to dao so web/fofo can reuse the batch infra; fix empty-IMEI NPE in getInventoryItemMap that broke /offer/process for partners with no billed/scanned serials |
|
| 36334 |
2 d 23 h |
ranu |
/trunk/ |
rbm rating dashboard view commited |
|
| 36333 |
2 d 23 h |
amit |
/trunk/profitmandi-dao/src/main/java/com/spice/profitmandi/service/ |
Fix IllegalStateException: drop 'unless' when using @Cacheable(sync=true)
Spring Cache rejects @Cacheable with both sync=true AND an 'unless' attribute,
throwing IllegalStateException on every invocation. Surfaced in production log
on smartdukaan — MonitorController.todayPORBM:739 was returning 500 on 40
observed calls this session.
Dropped 'unless'. Caching an occasionally-empty List for 5 min is harmless:
months with no sales produce an empty result, which is cheaper to re-query
after 5 min than to keep special-casing. The real fix driver for sync=true
(stampede protection) is preserved. |
|
| 36332 |
2 d 23 h |
amit |
/trunk/profitmandi-dao/src/main/java/com/spice/profitmandi/service/transaction/ |
moveToBill: fix loop reassigning order back to worse warehouse
- Break after first warehouse that covers remaining qty; loop used to
fall through and overwrite fulfilment WH with every subsequent snapshot,
so orders ended up pinned to the last (least-available) candidate.
- Sort candidates by net availability (availability - reserved) desc
so the best warehouse is tried first.
- Track remainingQty across splits; keep current orderId on the chunk
being placed and move the leftover to the deferred order.
- Null guard on itemSnapshots when no vendor under the billing WH has
stock/reservation for the item. |
|
| 36331 |
3 d 0 h |
amit |
/trunk/profitmandi-dao/src/main/java/com/spice/profitmandi/service/inventory/ |
Fix @Cacheable name collision between getSaholicStockList variants
SaholicInventoryServiceImpl:271 and :282 both used @Cacheable(value =
'saholicCISList') on no-arg methods. Spring's default SimpleKey.EMPTY means
both methods shared ONE cache entry — whichever was called first poisoned the
cache for the other, even though they return different filtered sets:
- getSaholicStockList (:272) runs selectWarehouseCisNew — tl.active=1 only
- getSaholicStockListWithoutCatalogMovingStatus (:283) runs
selectWarehouseCisNewWithoutCatalogMovingStatus — includes catalog moving
status join and filters out non-stocked OTHER/SLOWMOVING items
Renamed the second cache to 'saholicCISListWithStatus' so each method uses
its own namespace. Consumers of either method now get their method's actual
result, not a random earlier caller's.
This is a correctness fix (wrong cached data) more than a perf fix, though
it does mean both caches fill independently now (tiny cold-path DB uptick,
already mitigated by 5-min TTL via timeoutCacheManager). |
|
| 36329 |
3 d 1 h |
amit |
/trunk/profitmandi-dao/src/main/java/com/spice/profitmandi/service/ |
Tune rbmWeeklyBilling cache: 2m→5m TTL + sync=true
The RBM weekly billing aggregate query takes ~2s per call (1,924 cumulative hits
on hadb1 = 3,800s DB time). Previously cached for only 2 minutes with no
stampede protection — every 2m window, every concurrent dashboard load ran the
aggregate in parallel and burnt Hikari slots simultaneously.
- 2m → 5m: this is month-level aggregate bucketed by week, doesn't need
sub-minute freshness for an RBM dashboard.
- sync=true: single in-JVM computation per (monthStart, monthEnd) key per
expiry window; concurrent misses wait for the in-flight load instead of
racing to the DB.
fiveMintimeoutCacheManager already exists in CacheConfig:73 (Caffeine, in-memory,
so no Redis/LocalDateTime serialization concerns). |
|
| 36327 |
3 d 3 h |
amit |
/trunk/profitmandi-dao/src/main/java/com/spice/profitmandi/ |
Fix currentinventorysnapshot/currentreservationsnapshot deadlock and optimize getFirstBillingDate
- SaholicInventoryServiceImpl: enforce reservation-snapshot → inventory-snapshot
lock order in addReservationCount and reduceReservationCount via explicit
session.flush(); eliminates the hadb1 deadlock recorded 2026-04-20 19:43:24
between these two methods' opposite-order writes.
- SaholicInventorySnapshot: add @DynamicUpdate so UPDATEs only rewrite the
changed column instead of all three — cuts redo/binlog write amplification
and makes deadlock dumps pinpoint the actual business path.
- TransactionRepositoryImpl.getFirstBillingDate: replace filesort-over-all-billed-
orders with MIN(billingTimestamp) via new Order.selectFirstBillingByRetailer
named query (Select tables optimized away). Preserves 2017-01-01 cutoff and
null-for-unbilled-partner semantics.
- Add @Cacheable on redisOneDayCacheManager keyed by fofoId (unless null) so the
8 call sites stop piling up identical SELECTs on the order table — this was
the query pinning Hikari slots at 150-460s each in recent processlist dumps. |
|