You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2020/12/29 03:28:17 UTC
[GitHub] [iotdb] SilverNarcissus commented on a change in pull request #2350: [To rel/0.11] [IOTDB-1069] restrict the flushing memtable number to avoid OOM when mem_control is disabled
SilverNarcissus commented on a change in pull request #2350:
URL: https://github.com/apache/iotdb/pull/2350#discussion_r549552799
##########
File path: server/src/main/java/org/apache/iotdb/db/rescon/MemTableManager.java
##########
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iotdb.db.rescon;
+
+import org.apache.iotdb.db.conf.IoTDBConfig;
+import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.engine.memtable.IMemTable;
+import org.apache.iotdb.db.engine.memtable.PrimitiveMemTable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MemTableManager {
+
+ private static final IoTDBConfig CONFIG = IoTDBDescriptor.getInstance().getConfig();
+
+ private static final Logger logger = LoggerFactory.getLogger(MemTableManager.class);
+
+ private static final int WAIT_TIME = 100;
+ public static final int MEMTABLE_NUM_FOR_EACH_PARTITION = 4;
+ private int currentMemtableNumber = 0;
+
+ private MemTableManager() {
+ }
+
+ public static MemTableManager getInstance() {
+ return InstanceHolder.INSTANCE;
+ }
+
+ /**
+ * Called when memory control is disabled
+ */
+ public synchronized IMemTable getAvailableMemTable(String storageGroup) {
+ if (!reachMaxMemtableNumber()) {
+ currentMemtableNumber++;
+ return new PrimitiveMemTable();
+ } else {
+ // wait until the total memtable number is less than the capacity of the system
+ int waitCount = 1;
+ while (true) {
+ if (!reachMaxMemtableNumber()) {
+ currentMemtableNumber++;
+ return new PrimitiveMemTable();
+ }
+ try {
+ wait(WAIT_TIME);
Review comment:
We shouldn't use wait without notify. We should notifyAll at "decreaseMemtableNumber"
##########
File path: server/src/main/java/org/apache/iotdb/db/rescon/MemTableManager.java
##########
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iotdb.db.rescon;
+
+import org.apache.iotdb.db.conf.IoTDBConfig;
+import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.engine.memtable.IMemTable;
+import org.apache.iotdb.db.engine.memtable.PrimitiveMemTable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MemTableManager {
+
+ private static final IoTDBConfig CONFIG = IoTDBDescriptor.getInstance().getConfig();
+
+ private static final Logger logger = LoggerFactory.getLogger(MemTableManager.class);
+
+ private static final int WAIT_TIME = 100;
+ public static final int MEMTABLE_NUM_FOR_EACH_PARTITION = 4;
+ private int currentMemtableNumber = 0;
+
+ private MemTableManager() {
+ }
+
+ public static MemTableManager getInstance() {
+ return InstanceHolder.INSTANCE;
+ }
+
+ /**
+ * Called when memory control is disabled
+ */
+ public synchronized IMemTable getAvailableMemTable(String storageGroup) {
+ if (!reachMaxMemtableNumber()) {
+ currentMemtableNumber++;
+ return new PrimitiveMemTable();
+ } else {
+ // wait until the total memtable number is less than the capacity of the system
+ int waitCount = 1;
+ while (true) {
+ if (!reachMaxMemtableNumber()) {
+ currentMemtableNumber++;
+ return new PrimitiveMemTable();
+ }
+ try {
+ wait(WAIT_TIME);
+ } catch (InterruptedException e) {
+ logger.error("{} fails to wait for memtables {}, continue to wait", storageGroup, e);
+ Thread.currentThread().interrupt();
Review comment:
After interrupt. We should also throw the exception. Or this will loop forever without wait. (When enter wait with interrupt, wait will just return without wait.)
##########
File path: server/src/main/java/org/apache/iotdb/db/rescon/MemTableManager.java
##########
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iotdb.db.rescon;
+
+import org.apache.iotdb.db.conf.IoTDBConfig;
+import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.engine.memtable.IMemTable;
+import org.apache.iotdb.db.engine.memtable.PrimitiveMemTable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MemTableManager {
+
+ private static final IoTDBConfig CONFIG = IoTDBDescriptor.getInstance().getConfig();
+
+ private static final Logger logger = LoggerFactory.getLogger(MemTableManager.class);
+
+ private static final int WAIT_TIME = 100;
+ public static final int MEMTABLE_NUM_FOR_EACH_PARTITION = 4;
+ private int currentMemtableNumber = 0;
+
+ private MemTableManager() {
+ }
+
+ public static MemTableManager getInstance() {
+ return InstanceHolder.INSTANCE;
+ }
+
+ /**
+ * Called when memory control is disabled
+ */
+ public synchronized IMemTable getAvailableMemTable(String storageGroup) {
+ if (!reachMaxMemtableNumber()) {
+ currentMemtableNumber++;
+ return new PrimitiveMemTable();
+ } else {
+ // wait until the total memtable number is less than the capacity of the system
+ int waitCount = 1;
+ while (true) {
+ if (!reachMaxMemtableNumber()) {
+ currentMemtableNumber++;
+ return new PrimitiveMemTable();
+ }
+ try {
+ wait(WAIT_TIME);
+ } catch (InterruptedException e) {
+ logger.error("{} fails to wait for memtables {}, continue to wait", storageGroup, e);
+ Thread.currentThread().interrupt();
+ }
+ if (waitCount++ % 10 == 0) {
+ logger.info("{} has waited for a memtable for {}ms", storageGroup, waitCount * WAIT_TIME);
+ }
+ }
+ }
+ }
+
+ public synchronized int getCurrentMemtableNumber() {
+ return currentMemtableNumber;
+ }
+
+ public synchronized void addMemtableNumber() {
+ currentMemtableNumber++;
+ }
+
+ public synchronized void decreaseMemtableNumber() {
+ currentMemtableNumber--;
+ }
+
+ /**
+ * Called when memory control is disabled
+ */
+ private boolean reachMaxMemtableNumber() {
+ return currentMemtableNumber >= CONFIG.getMaxMemtableNumber();
+ }
+
+ /**
+ * Called when memory control is disabled
+ */
+ public synchronized void addOrDeleteStorageGroup(int diff) {
+ int maxMemTableNum = CONFIG.getMaxMemtableNumber();
+ maxMemTableNum += MEMTABLE_NUM_FOR_EACH_PARTITION
+ * CONFIG.getConcurrentWritingTimePartition() * diff;
+ CONFIG.setMaxMemtableNumber(maxMemTableNum);
Review comment:
Also notifyAll at here
##########
File path: server/src/main/java/org/apache/iotdb/db/rescon/MemTableManager.java
##########
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iotdb.db.rescon;
+
+import org.apache.iotdb.db.conf.IoTDBConfig;
+import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.engine.memtable.IMemTable;
+import org.apache.iotdb.db.engine.memtable.PrimitiveMemTable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MemTableManager {
+
+ private static final IoTDBConfig CONFIG = IoTDBDescriptor.getInstance().getConfig();
+
+ private static final Logger logger = LoggerFactory.getLogger(MemTableManager.class);
+
+ private static final int WAIT_TIME = 100;
+ public static final int MEMTABLE_NUM_FOR_EACH_PARTITION = 4;
+ private int currentMemtableNumber = 0;
+
+ private MemTableManager() {
+ }
+
+ public static MemTableManager getInstance() {
+ return InstanceHolder.INSTANCE;
+ }
+
+ /**
+ * Called when memory control is disabled
+ */
+ public synchronized IMemTable getAvailableMemTable(String storageGroup) {
+ if (!reachMaxMemtableNumber()) {
+ currentMemtableNumber++;
+ return new PrimitiveMemTable();
+ } else {
+ // wait until the total memtable number is less than the capacity of the system
+ int waitCount = 1;
+ while (true) {
+ if (!reachMaxMemtableNumber()) {
+ currentMemtableNumber++;
+ return new PrimitiveMemTable();
+ }
+ try {
+ wait(WAIT_TIME);
+ } catch (InterruptedException e) {
+ logger.error("{} fails to wait for memtables {}, continue to wait", storageGroup, e);
+ Thread.currentThread().interrupt();
+ }
+ if (waitCount++ % 10 == 0) {
+ logger.info("{} has waited for a memtable for {}ms", storageGroup, waitCount * WAIT_TIME);
+ }
+ }
+ }
+ }
+
+ public synchronized int getCurrentMemtableNumber() {
+ return currentMemtableNumber;
+ }
+
+ public synchronized void addMemtableNumber() {
+ currentMemtableNumber++;
+ }
+
+ public synchronized void decreaseMemtableNumber() {
+ currentMemtableNumber--;
Review comment:
NotifyAll at here
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org