Skip to content
Snippets Groups Projects
Commit c9791b32 authored by Ghazi Triki's avatar Ghazi Triki
Browse files

Use single connection for RedisStorageService instead of connection pool.

parent 79d34c42
No related branches found
No related tags found
No related merge requests found
...@@ -21,7 +21,6 @@ package org.bigbluebutton.common2.redis; ...@@ -21,7 +21,6 @@ package org.bigbluebutton.common2.redis;
import java.util.Map; import java.util.Map;
import org.apache.commons.pool2.impl.GenericObjectPool;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -30,13 +29,12 @@ import io.lettuce.core.RedisClient; ...@@ -30,13 +29,12 @@ import io.lettuce.core.RedisClient;
import io.lettuce.core.RedisURI; import io.lettuce.core.RedisURI;
import io.lettuce.core.api.StatefulRedisConnection; import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.sync.RedisCommands; import io.lettuce.core.api.sync.RedisCommands;
import io.lettuce.core.support.ConnectionPoolSupport;
public class RedisStorageService extends RedisAwareCommunicator { public class RedisStorageService extends RedisAwareCommunicator {
private static Logger log = LoggerFactory.getLogger(RedisStorageService.class); private static Logger log = LoggerFactory.getLogger(RedisStorageService.class);
GenericObjectPool<StatefulRedisConnection<String, String>> connectionPool; StatefulRedisConnection<String, String> connection;
public void start() { public void start() {
log.info("Starting RedisStorageService with client name: {}", clientName); log.info("Starting RedisStorageService with client name: {}", clientName);
...@@ -46,12 +44,11 @@ public class RedisStorageService extends RedisAwareCommunicator { ...@@ -46,12 +44,11 @@ public class RedisStorageService extends RedisAwareCommunicator {
redisClient = RedisClient.create(redisUri); redisClient = RedisClient.create(redisUri);
redisClient.setOptions(ClientOptions.builder().autoReconnect(true).build()); redisClient.setOptions(ClientOptions.builder().autoReconnect(true).build());
connectionPool = ConnectionPoolSupport.createGenericObjectPool(() -> redisClient.connect(), connection = redisClient.connect();
createPoolingConfig());
} }
public void stop() { public void stop() {
connectionPool.close(); connection.close();
redisClient.shutdown(); redisClient.shutdown();
log.info("RedisStorageService Stopped"); log.info("RedisStorageService Stopped");
} }
...@@ -68,67 +65,52 @@ public class RedisStorageService extends RedisAwareCommunicator { ...@@ -68,67 +65,52 @@ public class RedisStorageService extends RedisAwareCommunicator {
public void addBreakoutRoom(String parentId, String breakoutId) { public void addBreakoutRoom(String parentId, String breakoutId) {
log.debug("Saving breakout room for meeting {}", parentId); log.debug("Saving breakout room for meeting {}", parentId);
try (StatefulRedisConnection<String, String> connection = connectionPool.borrowObject()) { RedisCommands<String, String> commands = connection.sync();
RedisCommands<String, String> commands = connection.sync(); commands.sadd(Keys.BREAKOUT_ROOMS + parentId, breakoutId);
commands.sadd(Keys.BREAKOUT_ROOMS + parentId, breakoutId); connection.close();
} catch (Exception e) {
log.error("Cannot add breakout room data: {}", parentId, e);
}
} }
public void record(String meetingId, Map<String, String> event) { public void record(String meetingId, Map<String, String> event) {
log.debug("Recording meeting event {} inside a transaction", meetingId); log.debug("Recording meeting event {} inside a transaction", meetingId);
try (StatefulRedisConnection<String, String> connection = connectionPool.borrowObject()) { RedisCommands<String, String> commands = connection.sync();
RedisCommands<String, String> commands = connection.sync(); Long msgid = commands.incr("global:nextRecordedMsgId");
Long msgid = commands.incr("global:nextRecordedMsgId"); commands.hmset("recording:" + meetingId + ":" + msgid, event);
commands.hmset("recording:" + meetingId + ":" + msgid, event); commands.rpush("meeting:" + meetingId + ":" + "recordings", Long.toString(msgid));
commands.rpush("meeting:" + meetingId + ":" + "recordings", Long.toString(msgid)); connection.close();
} catch (Exception e) {
log.debug("Cannot record meeting data: {}", meetingId, e);
}
} }
// @fixme: not used anywhere // @fixme: not used anywhere
public void removeMeeting(String meetingId) { public void removeMeeting(String meetingId) {
log.debug("Removing meeting meeting {} inside a transaction", meetingId); log.debug("Removing meeting meeting {} inside a transaction", meetingId);
try (StatefulRedisConnection<String, String> connection = connectionPool.borrowObject()) { RedisCommands<String, String> commands = connection.sync();
RedisCommands<String, String> commands = connection.sync(); commands.del(Keys.MEETING + meetingId);
commands.del(Keys.MEETING + meetingId); commands.srem(Keys.MEETINGS + meetingId);
commands.srem(Keys.MEETINGS + meetingId); connection.close();
} catch (Exception e) {
log.debug("Cannot remove meeting data : {}", meetingId, e);
}
} }
public void recordAndExpire(String meetingId, Map<String, String> event) { public void recordAndExpire(String meetingId, Map<String, String> event) {
log.debug("Recording meeting event {} inside a transaction", meetingId); log.debug("Recording meeting event {} inside a transaction", meetingId);
try (StatefulRedisConnection<String, String> connection = connectionPool.borrowObject()) { RedisCommands<String, String> commands = connection.sync();
RedisCommands<String, String> commands = connection.sync();
Long msgid = commands.incr("global:nextRecordedMsgId");
Long msgid = commands.incr("global:nextRecordedMsgId"); commands.hmset("recording:" + meetingId + ":" + msgid, event);
commands.hmset("recording:" + meetingId + ":" + msgid, event); /**
/** * We set the key to expire after 14 days as we are still recording the
* We set the key to expire after 14 days as we are still recording * event into redis even if the meeting is not recorded. (ralam sept 23,
* the event into redis even if the meeting is not recorded. (ralam * 2015)
* sept 23, 2015) */
*/ commands.expire("meeting:" + meetingId + ":recordings", expireKey);
commands.expire("meeting:" + meetingId + ":recordings", expireKey); commands.rpush("meeting:" + meetingId + ":recordings", Long.toString(msgid));
commands.rpush("meeting:" + meetingId + ":recordings", Long.toString(msgid)); commands.expire("meeting:" + meetingId + ":recordings", expireKey);
commands.expire("meeting:" + meetingId + ":recordings", expireKey); connection.close();
} catch (Exception e) {
log.error("Cannot record data with expire: {}", meetingId, e);
}
} }
private String recordMeeting(String key, Map<String, String> info) { private String recordMeeting(String key, Map<String, String> info) {
log.debug("Storing metadata {}", info); log.debug("Storing metadata {}", info);
String result = ""; String result = "";
try (StatefulRedisConnection<String, String> connection = connectionPool.borrowObject()) { RedisCommands<String, String> commands = connection.sync();
RedisCommands<String, String> commands = connection.sync(); result = commands.hmset(key, info);
result = commands.hmset(key, info); connection.close();
} catch (Exception e) {
log.debug("Cannot record data with expire: {}", key, e);
}
return result; return result;
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment