forked from apolloconfig/apollo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Config service cache and namespace name normalization
1. Enable config cache to improve config service performance, just set config-service.cache.enabled to true in ServerConfig 2. Normalize the namespace name in case the one provided has character case issue
- Loading branch information
Showing
44 changed files
with
2,363 additions
and
500 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,31 @@ | ||
package com.ctrip.framework.apollo.biz.message; | ||
|
||
import com.google.common.collect.Lists; | ||
|
||
import com.ctrip.framework.apollo.biz.entity.ReleaseMessage; | ||
import com.ctrip.framework.apollo.biz.repository.ReleaseMessageRepository; | ||
import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory; | ||
import com.ctrip.framework.apollo.tracer.Tracer; | ||
import com.ctrip.framework.apollo.tracer.spi.Transaction; | ||
import java.util.List; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.InitializingBean; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.util.CollectionUtils; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
import com.ctrip.framework.apollo.biz.config.BizConfig; | ||
import com.ctrip.framework.apollo.biz.entity.ReleaseMessage; | ||
import com.ctrip.framework.apollo.biz.repository.ReleaseMessageRepository; | ||
import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory; | ||
import com.ctrip.framework.apollo.tracer.Tracer; | ||
import com.ctrip.framework.apollo.tracer.spi.Transaction; | ||
import com.google.common.collect.Lists; | ||
|
||
/** | ||
* @author Jason Song([email protected]) | ||
*/ | ||
public class ReleaseMessageScanner implements InitializingBean { | ||
private static final Logger logger = LoggerFactory.getLogger(ReleaseMessageScanner.class); | ||
private static final int DEFAULT_SCAN_INTERVAL_IN_MS = 1000; | ||
@Autowired | ||
private Environment env; | ||
private BizConfig bizConfig; | ||
@Autowired | ||
private ReleaseMessageRepository releaseMessageRepository; | ||
private int databaseScanInterval; | ||
|
@@ -44,7 +41,7 @@ public ReleaseMessageScanner() { | |
|
||
@Override | ||
public void afterPropertiesSet() throws Exception { | ||
populateDataBaseInterval(); | ||
databaseScanInterval = bizConfig.releaseMessageScanIntervalInMilli(); | ||
maxIdScanned = loadLargestMessageId(); | ||
executorService.scheduleWithFixedDelay((Runnable) () -> { | ||
Transaction transaction = Tracer.newTransaction("Apollo.ReleaseMessageScanner", "scanMessage"); | ||
|
@@ -57,7 +54,7 @@ public void afterPropertiesSet() throws Exception { | |
} finally { | ||
transaction.complete(); | ||
} | ||
}, getDatabaseScanIntervalMs(), getDatabaseScanIntervalMs(), TimeUnit.MILLISECONDS); | ||
}, databaseScanInterval, databaseScanInterval, TimeUnit.MILLISECONDS); | ||
|
||
} | ||
|
||
|
@@ -124,21 +121,4 @@ private void fireMessageScanned(List<ReleaseMessage> messages) { | |
} | ||
} | ||
} | ||
|
||
private void populateDataBaseInterval() { | ||
databaseScanInterval = DEFAULT_SCAN_INTERVAL_IN_MS; | ||
try { | ||
String interval = env.getProperty("apollo.message-scan.interval"); | ||
if (!Objects.isNull(interval)) { | ||
databaseScanInterval = Integer.parseInt(interval); | ||
} | ||
} catch (Throwable ex) { | ||
Tracer.logError(ex); | ||
logger.error("Load apollo message scan interval from system property failed", ex); | ||
} | ||
} | ||
|
||
private int getDatabaseScanIntervalMs() { | ||
return databaseScanInterval; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,9 +12,11 @@ | |
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.Mockito.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.never; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
/** | ||
* @author Jason Song([email protected]) | ||
|
@@ -33,6 +35,11 @@ public void setUp() throws Exception { | |
@Test | ||
public void testSendMessage() throws Exception { | ||
String someMessage = "some-message"; | ||
long someId = 1; | ||
ReleaseMessage someReleaseMessage = mock(ReleaseMessage.class); | ||
when(someReleaseMessage.getId()).thenReturn(someId); | ||
when(releaseMessageRepository.save(any(ReleaseMessage.class))).thenReturn(someReleaseMessage); | ||
|
||
ArgumentCaptor<ReleaseMessage> captor = ArgumentCaptor.forClass(ReleaseMessage.class); | ||
|
||
messageSender.sendMessage(someMessage, Topics.APOLLO_RELEASE_TOPIC); | ||
|
@@ -50,4 +57,12 @@ public void testSendUnsupportedMessage() throws Exception { | |
|
||
verify(releaseMessageRepository, never()).save(any(ReleaseMessage.class)); | ||
} | ||
|
||
@Test(expected = RuntimeException.class) | ||
public void testSendMessageFailed() throws Exception { | ||
String someMessage = "some-message"; | ||
when(releaseMessageRepository.save(any(ReleaseMessage.class))).thenThrow(new RuntimeException()); | ||
|
||
messageSender.sendMessage(someMessage, Topics.APOLLO_RELEASE_TOPIC); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.