In addition to the quota, there are two watermarks the engine will use to determine when it is necessary to start freeing up available memory. These are mem_low_wat and mem_high_wat.
As the system is loaded with data, eventually the mem_low_wat is passed. At this time, a background job is scheduled to reclaim the cached values of replica items from RAM...freeing up memory for further data growth. This is called "ejection" and can only take place on items that have already been written to disk...marking them as "clean". As data continues to load, it will evenutally reach/pass mem_high_wat. The job will continue to run, now ejecting active items as well until memory is below mem_low_wat. If the rate of incoming items is faster than the writing of items to disk, the system may return errors indicating there is not enough space. This will continue until there is available memory.
Currently, we have implemented option 2. The handling of SERVER_ERROR is required by the client.(目前空間不足時,只返回SERVER_ERROR)
Get FlowThe actual process of eviction is relatively simple now. When we need memory, we look around in hash tables and attempt to find things we can get rid of (i.e.things that are persisted on disk) andstart dropping it. We will also eject data as soon as it's persisted iff it's for an inactive (e.g. replica) vbucket