flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] StefanRRichter commented on a change in pull request #6814: [FLINK-10423][rocksdb][metrics] rocksdb native metrics monitor
Date Thu, 11 Oct 2018 17:32:17 GMT
StefanRRichter commented on a change in pull request #6814: [FLINK-10423][rocksdb][metrics]
rocksdb native metrics monitor
URL: https://github.com/apache/flink/pull/6814#discussion_r224534588
 
 

 ##########
 File path: flink-state-backends/flink-statebackend-rocksdb/src/main/java/org/apache/flink/contrib/streaming/state/RocksDBNativeMetricMonitor.java
 ##########
 @@ -0,0 +1,154 @@
+/*
+ * 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.flink.contrib.streaming.state;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.core.fs.CloseableRegistry;
+import org.apache.flink.metrics.Gauge;
+import org.apache.flink.metrics.MetricGroup;
+import org.apache.flink.metrics.View;
+import org.apache.flink.util.FlinkRuntimeException;
+import org.apache.flink.util.IOUtils;
+import org.apache.flink.util.ResourceGuard;
+
+import org.rocksdb.ColumnFamilyHandle;
+import org.rocksdb.RocksDB;
+import org.rocksdb.RocksDBException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Nonnull;
+
+import java.io.Closeable;
+import java.io.IOException;
+
+/**
+ * A monitor which pull {{@link RocksDB}} native metrics
+ * and forwards them to Flink's metric group. All metrics are
+ * unsigned longs and are reported at the column family level.
+ */
+@Internal
+public class RocksDBNativeMetricMonitor implements Closeable {
+
+	private final CloseableRegistry registeredGauges;
+
+	private final RocksDB db;
+
+	private final ResourceGuard.Lease lease;
+
+	private final RocksDBNativeMetricOptions options;
+
+	private final MetricGroup metricGroup;
+
+	RocksDBNativeMetricMonitor(
+		@Nonnull RocksDB db,
+		@Nonnull ResourceGuard guard,
+		@Nonnull RocksDBNativeMetricOptions options,
+		@Nonnull MetricGroup metricGroup
+	) throws IOException {
+		this.db = db;
+		this.lease = guard.acquireResource();
+		this.options = options;
+		this.metricGroup = metricGroup;
+
+		this.registeredGauges = new CloseableRegistry();
+	}
+
+	/**
+	 * Register gauges to pull native metrics for the column family.
+	 * @param columnFamilyName group name for the new gauges
+	 * @param handle native handle to the column family
+	 */
+	void registerColumnFamily(String columnFamilyName, ColumnFamilyHandle handle) {
+		try {
+			MetricGroup group = metricGroup.addGroup(columnFamilyName);
+
+			for (String property : options.getProperties()) {
+				RocksDBNativeMetricView gauge = new RocksDBNativeMetricView(
+					property,
+					handle,
+					db
+				);
+
+				group.gauge(property, gauge);
+				registeredGauges.registerCloseable(gauge);
+			}
+		} catch (IOException e) {
+			throw new FlinkRuntimeException("Unable to register native metrics with RocksDB", e);
+		}
+	}
+
+	@Override
+	public void close() {
+		IOUtils.closeQuietly(registeredGauges);
+		IOUtils.closeQuietly(lease);
+	}
+
+	static class RocksDBNativeMetricView implements Gauge<String>, View, Closeable {
+		private static final Logger LOG = LoggerFactory.getLogger(RocksDBNativeMetricView.class);
+
+		private final String property;
+
+		private final ColumnFamilyHandle handle;
+
+		private final RocksDB db;
+
+		private volatile boolean open;
+
+		private long value;
+
+		private RocksDBNativeMetricView(
+			@Nonnull String property,
+			@Nonnull ColumnFamilyHandle handle,
+			@Nonnull RocksDB db
+		) {
+			this.property = property;
+			this.handle = handle;
+			this.db = db;
+			this.open = true;
+		}
+
+		@Override
+		public String getValue() {
+			return Long.toUnsignedString(value);
+		}
+
+		@Override
+		public void update() {
+			if (open) {
 
 Review comment:
   One way of doing this correctly could be to aquire a lease before reading and releasing
the lease when the read is complete. Using state transitions (open, readlocked, closed) via
AtomicRefernces could also work. However, I think there is potential for better approaches
if the metrics system supports it, e.g. if there is a threadpool used to run the updates per
task, then we could first shutdown the metrics threads and then dispose other resources like
the backends. What would be desirable is that the metrics pulling threads are pooled, and
when the pool is closed we are sure that there are no more in-flight update calls. This could
eliminate the need for `volatile`, `lease` or other synchronnization measures.
   @zentol is there a way to shut down the metrics pulling in such a fashion, where we are
sure that no more updates are pending or triggered in the future?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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


With regards,
Apache Git Services

Mime
View raw message