From 73aef1482027e3efb66ffe4c8443e25c790cfc23 Mon Sep 17 00:00:00 2001 From: bigsheeper Date: Fri, 15 Jul 2022 10:22:27 +0800 Subject: [PATCH] Improve check of purge memory and change purge place (#18271) Signed-off-by: bigsheeper --- internal/core/src/common/memory_c.cpp | 5 ++++- internal/querynode/reduce.go | 5 ++++- internal/querynode/task_search.go | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/core/src/common/memory_c.cpp b/internal/core/src/common/memory_c.cpp index c0808635e8..4d79a6058e 100644 --- a/internal/core/src/common/memory_c.cpp +++ b/internal/core/src/common/memory_c.cpp @@ -43,6 +43,7 @@ ParseMallocInfo() { size_t buffer_size; FILE* stream; stream = open_memstream(&mem_buffer, &buffer_size); + AssertInfo(stream, "null stream file when open_memstream"); // malloc_info(0, stdout); /* @@ -55,13 +56,15 @@ ParseMallocInfo() { * * */ - malloc_info(0, stream); + auto ret = malloc_info(0, stream); + AssertInfo(ret == 0, "malloc_info failed"); fflush(stream); rapidxml::xml_document<> doc; // character type defaults to char doc.parse<0>(mem_buffer); // 0 means default parse flags rapidxml::xml_node<>* malloc_root_node = doc.first_node(); + AssertInfo(malloc_root_node, "null malloc_root_node detected when ParseMallocInfo"); auto total_fast_node = malloc_root_node->first_node()->next_sibling("total"); AssertInfo(total_fast_node, "null total_fast_node detected when ParseMallocInfo"); auto total_fast_size = std::stoul(total_fast_node->first_attribute("size")->value()); diff --git a/internal/querynode/reduce.go b/internal/querynode/reduce.go index eb1d9ffe71..7da2c08887 100644 --- a/internal/querynode/reduce.go +++ b/internal/querynode/reduce.go @@ -137,7 +137,10 @@ func getSearchResultDataBlob(cSearchResultDataBlobs searchResultDataBlobs, blobI func deleteSearchResultDataBlobs(cSearchResultDataBlobs searchResultDataBlobs) { C.DeleteSearchResultDataBlobs(cSearchResultDataBlobs) - // try to do a purgeMemory operation after DeleteSearchResultDataBlobs +} + +func purgeMemoryAfterReduce() { + // try to do a purgeMemory operation after reduce usedMem := metricsinfo.GetUsedMemoryCount() if usedMem == 0 { log.Error("Get 0 usedMemory when deleteSearchResultDataBlobs, which is unexpected") diff --git a/internal/querynode/task_search.go b/internal/querynode/task_search.go index 8cf80b5538..881d77d99b 100644 --- a/internal/querynode/task_search.go +++ b/internal/querynode/task_search.go @@ -120,6 +120,7 @@ func (s *searchTask) searchOnStreaming() error { zap.Int64("collectionID", s.CollectionID), zap.Error(sErr)) return sErr } + defer purgeMemoryAfterReduce() defer deleteSearchResults(partResults) return s.reduceResults(searchReq, partResults) } @@ -155,6 +156,7 @@ func (s *searchTask) searchOnHistorical() error { if err != nil { return err } + defer purgeMemoryAfterReduce() defer deleteSearchResults(partResults) return s.reduceResults(searchReq, partResults) }