tryEviction : try to trigger eviction once unManagedMem + managedMem > totalAssignedMem. This method will pop batches from the per column holder data structure, calculate global priority based on column metadata, then push the batch into a priority queue. Eviction will happen through all the populat
()
| 404 | // decreases to a certain level. All failed eviction batches will be |
| 405 | // reinserted. |
| 406 | func (h *hostMemoryManager) tryEviction() { |
| 407 | // Check if eviction should be triggered |
| 408 | if (h.totalMemorySize - h.getManagedSpaceUsage() - h.getUnmanagedSpaceUsage()) < 0 { |
| 409 | utils.GetLogger().Debugf("UnmanagedMem: %d + ManagedMem: %d is larger than totalMem: %d! Eviction is triggered.", |
| 410 | h.getUnmanagedSpaceUsage(), h.getManagedSpaceUsage(), h.totalMemorySize) |
| 411 | // Init all columnar priority batches. |
| 412 | gpq := h.initialGlobalPriorityQueue() |
| 413 | // Pop from globalPriorityQueueWithLock and do eviction |
| 414 | for (h.totalMemorySize-h.getManagedSpaceUsage()-h.getUnmanagedSpaceUsage()) < 0 && !gpq.isEmpty() { |
| 415 | globalPriorityItem := gpq.pop() |
| 416 | |
| 417 | batchPriority := globalPriorityItem.priority |
| 418 | columnBatchInfos := globalPriorityItem.value |
| 419 | columnIt := globalPriorityItem.it |
| 420 | |
| 421 | tableSchema, err := h.memStore.GetSchema(columnBatchInfos.table) |
| 422 | |
| 423 | tableSchema.RLock() |
| 424 | preloadingDays := tableSchema.Schema.Columns[batchPriority.columnID].Config.PreloadingDays |
| 425 | tableSchema.RUnlock() |
| 426 | |
| 427 | isPreloadingDays := isPreloadingBatch(batchPriority.batchID, preloadingDays) |
| 428 | |
| 429 | if isPreloadingDays { |
| 430 | utils.GetReporter(columnBatchInfos.table, batchPriority.shardID). |
| 431 | GetCounter(utils.PreloadingZoneEvicted).Inc(1) |
| 432 | utils.GetLogger().With( |
| 433 | "table", columnBatchInfos.table, |
| 434 | "shard", batchPriority.shardID, |
| 435 | "batch", batchPriority.batchID, |
| 436 | "column", batchPriority.columnID, |
| 437 | ).Warn("Column in preloading zone is evicted") |
| 438 | } |
| 439 | |
| 440 | ok, err := h.memStore.TryEvictBatchColumn(columnBatchInfos.table, batchPriority.shardID, int32(batchPriority.batchID), batchPriority.columnID) |
| 441 | if ok { |
| 442 | utils.GetLogger().Debugf("Successfully evict batch from memstore: table %s, shardID %d, batchID %d, columnID %d, size %d", |
| 443 | columnBatchInfos.table, batchPriority.shardID, batchPriority.batchID, batchPriority.columnID, batchPriority.size) |
| 444 | } else { |
| 445 | utils.GetLogger().Debugf("Failed to evict batch from memstore: table %s, shardID %d, batchID %d, columnID %d, size %d, errors: %s", |
| 446 | columnBatchInfos.table, batchPriority.shardID, batchPriority.batchID, batchPriority.columnID, batchPriority.size, err) |
| 447 | } |
| 448 | |
| 449 | // Adding the corresponding next batch into priority queue. |
| 450 | if columnIt.Next() { |
| 451 | gpq.pushBatchIntoGlobalPriorityQueue(h, columnBatchInfos, batchPriority.columnID, columnIt) |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | // Still cannot meet the memory constraints even after evictions. |
| 456 | if h.totalMemorySize-h.getManagedSpaceUsage()-h.getUnmanagedSpaceUsage() < 0 { |
| 457 | utils.GetRootReporter().GetCounter(utils.MemoryOverflow).Inc(1) |
| 458 | utils.GetLogger().Warn("Still cannot meet the memory constraints even after evictions") |
| 459 | } |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | // pushBatchIntoGlobalPriorityQueue will generate a globalPriority object then |
no test coverage detected