Merge remote-tracking branch 'origin/master' into develop/3.0

This commit is contained in:
Andrii Shvaika 2020-04-30 20:40:08 +03:00
commit c6cf5c43ad
3 changed files with 19 additions and 12 deletions

View File

@ -46,7 +46,7 @@ public class PsqlTsDatabaseUpgradeService extends AbstractSqlTsDatabaseUpgradeSe
private static final String CREATE_PARTITION_TS_KV_TABLE = "create_partition_ts_kv_table()"; private static final String CREATE_PARTITION_TS_KV_TABLE = "create_partition_ts_kv_table()";
private static final String CREATE_NEW_TS_KV_LATEST_TABLE = "create_new_ts_kv_latest_table()"; private static final String CREATE_NEW_TS_KV_LATEST_TABLE = "create_new_ts_kv_latest_table()";
private static final String CREATE_PARTITIONS = "create_partitions()"; private static final String CREATE_PARTITIONS = "create_partitions(IN partition_type varchar)";
private static final String CREATE_TS_KV_DICTIONARY_TABLE = "create_ts_kv_dictionary_table()"; private static final String CREATE_TS_KV_DICTIONARY_TABLE = "create_ts_kv_dictionary_table()";
private static final String INSERT_INTO_DICTIONARY = "insert_into_dictionary()"; private static final String INSERT_INTO_DICTIONARY = "insert_into_dictionary()";
private static final String INSERT_INTO_TS_KV = "insert_into_ts_kv()"; private static final String INSERT_INTO_TS_KV = "insert_into_ts_kv()";
@ -108,7 +108,6 @@ public class PsqlTsDatabaseUpgradeService extends AbstractSqlTsDatabaseUpgradeSe
executeQuery(conn, DROP_PROCEDURE_INSERT_INTO_TS_KV); executeQuery(conn, DROP_PROCEDURE_INSERT_INTO_TS_KV);
executeQuery(conn, DROP_PROCEDURE_CREATE_NEW_TS_KV_LATEST_TABLE); executeQuery(conn, DROP_PROCEDURE_CREATE_NEW_TS_KV_LATEST_TABLE);
executeQuery(conn, DROP_PROCEDURE_INSERT_INTO_TS_KV_LATEST); executeQuery(conn, DROP_PROCEDURE_INSERT_INTO_TS_KV_LATEST);
executeQuery(conn, DROP_PROCEDURE_INSERT_INTO_TS_KV_LATEST);
executeQuery(conn, DROP_FUNCTION_GET_PARTITION_DATA); executeQuery(conn, DROP_FUNCTION_GET_PARTITION_DATA);
executeQuery(conn, "ALTER TABLE ts_kv ADD COLUMN IF NOT EXISTS json_v json;"); executeQuery(conn, "ALTER TABLE ts_kv ADD COLUMN IF NOT EXISTS json_v json;");

View File

@ -81,14 +81,24 @@ public class TbKafkaConsumerTemplate<T extends TbQueueMsg> implements TbQueueCon
@Override @Override
public void subscribe() { public void subscribe() {
consumerLock.lock();
try {
partitions = Collections.singleton(new TopicPartitionInfo(topic, null, null, true)); partitions = Collections.singleton(new TopicPartitionInfo(topic, null, null, true));
subscribed = false; subscribed = false;
} finally {
consumerLock.unlock();
}
} }
@Override @Override
public void subscribe(Set<TopicPartitionInfo> partitions) { public void subscribe(Set<TopicPartitionInfo> partitions) {
consumerLock.lock();
try {
this.partitions = partitions; this.partitions = partitions;
subscribed = false; subscribed = false;
} finally {
consumerLock.unlock();
}
} }
@Override @Override
@ -100,13 +110,11 @@ public class TbKafkaConsumerTemplate<T extends TbQueueMsg> implements TbQueueCon
log.debug("Failed to await subscription", e); log.debug("Failed to await subscription", e);
} }
} else { } else {
try {
consumerLock.lock(); consumerLock.lock();
try {
if (!subscribed) { if (!subscribed) {
List<String> topicNames = partitions.stream().map(TopicPartitionInfo::getFullTopicName).collect(Collectors.toList()); List<String> topicNames = partitions.stream().map(TopicPartitionInfo::getFullTopicName).collect(Collectors.toList());
topicNames.forEach(admin::createTopicIfNotExists); topicNames.forEach(admin::createTopicIfNotExists);
consumer.unsubscribe();
consumer.subscribe(topicNames); consumer.subscribe(topicNames);
subscribed = true; subscribed = true;
} }
@ -132,8 +140,8 @@ public class TbKafkaConsumerTemplate<T extends TbQueueMsg> implements TbQueueCon
@Override @Override
public void commit() { public void commit() {
try {
consumerLock.lock(); consumerLock.lock();
try {
consumer.commitAsync(); consumer.commitAsync();
} finally { } finally {
consumerLock.unlock(); consumerLock.unlock();
@ -142,8 +150,8 @@ public class TbKafkaConsumerTemplate<T extends TbQueueMsg> implements TbQueueCon
@Override @Override
public void unsubscribe() { public void unsubscribe() {
try {
consumerLock.lock(); consumerLock.lock();
try {
if (consumer != null) { if (consumer != null) {
consumer.unsubscribe(); consumer.unsubscribe();
consumer.close(); consumer.close();

View File

@ -28,7 +28,7 @@ services:
ZOO_SERVERS: server.1=zookeeper:2888:3888;zookeeper:2181 ZOO_SERVERS: server.1=zookeeper:2888:3888;zookeeper:2181
kafka: kafka:
restart: always restart: always
image: "wurstmeister/kafka:2.12-2.2.1" image: "wurstmeister/kafka:2.12-2.3.0"
ports: ports:
- "9092:9092" - "9092:9092"
env_file: env_file: