MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / dbcOptionsFromConfig

Function dbcOptionsFromConfig

rest/server_context.go:1172–1480  ·  view source on GitHub ↗
(ctx context.Context, sc *ServerContext, config *DbConfig, dbName string)

Source from the content-addressed store, hash-verified

1170}
1171
1172func dbcOptionsFromConfig(ctx context.Context, sc *ServerContext, config *DbConfig, dbName string) (db.DatabaseContextOptions, error) {
1173
1174 // Get timeout to use for import filter function and db context
1175 javascriptTimeout := getJavascriptTimeout(config)
1176
1177 // Identify import options
1178 importOptions := newBaseImportOptions(config, sc.Config.IsServerless())
1179
1180 // Check for deprecated cache options. If new are set they will take priority but will still log warnings
1181 warnings := config.deprecatedConfigCacheFallback()
1182 for _, warnLog := range warnings {
1183 base.WarnfCtx(ctx, "%s", warnLog)
1184 }
1185 // Set cache properties, if present
1186 cacheOptions := db.DefaultCacheOptions()
1187 revCacheOptions := db.DefaultRevisionCacheOptions()
1188 if config.CacheConfig != nil {
1189 if config.CacheConfig.ChannelCacheConfig != nil {
1190 if config.CacheConfig.ChannelCacheConfig.MaxNumPending != nil {
1191 cacheOptions.CachePendingSeqMaxNum = *config.CacheConfig.ChannelCacheConfig.MaxNumPending
1192 }
1193 if config.CacheConfig.ChannelCacheConfig.MaxWaitPending != nil {
1194 cacheOptions.CachePendingSeqMaxWait = time.Duration(*config.CacheConfig.ChannelCacheConfig.MaxWaitPending) * time.Millisecond
1195 }
1196 if config.CacheConfig.ChannelCacheConfig.MaxWaitSkipped != nil {
1197 cacheOptions.CacheSkippedSeqMaxWait = time.Duration(*config.CacheConfig.ChannelCacheConfig.MaxWaitSkipped) * time.Millisecond
1198 }
1199 if config.CacheConfig.ChannelCacheConfig.MaxLength != nil {
1200 cacheOptions.ChannelCacheMaxLength = *config.CacheConfig.ChannelCacheConfig.MaxLength
1201 }
1202 if config.CacheConfig.ChannelCacheConfig.MinLength != nil {
1203 cacheOptions.ChannelCacheMinLength = *config.CacheConfig.ChannelCacheConfig.MinLength
1204 }
1205 if config.CacheConfig.ChannelCacheConfig.ExpirySeconds != nil {
1206 cacheOptions.ChannelCacheAge = time.Duration(*config.CacheConfig.ChannelCacheConfig.ExpirySeconds) * time.Second
1207 }
1208 if config.CacheConfig.ChannelCacheConfig.MaxNumber != nil {
1209 cacheOptions.MaxNumChannels = *config.CacheConfig.ChannelCacheConfig.MaxNumber
1210 }
1211 if config.CacheConfig.ChannelCacheConfig.HighWatermarkPercent != nil && *config.CacheConfig.ChannelCacheConfig.HighWatermarkPercent > 0 {
1212 cacheOptions.CompactHighWatermarkPercent = *config.CacheConfig.ChannelCacheConfig.HighWatermarkPercent
1213 }
1214 if config.CacheConfig.ChannelCacheConfig.HighWatermarkPercent != nil && *config.CacheConfig.ChannelCacheConfig.HighWatermarkPercent > 0 {
1215 cacheOptions.CompactLowWatermarkPercent = *config.CacheConfig.ChannelCacheConfig.HighWatermarkPercent
1216 }
1217 }
1218
1219 if config.CacheConfig.RevCacheConfig != nil {
1220 if config.CacheConfig.RevCacheConfig.MaxItemCount != nil {
1221 revCacheOptions.MaxItemCount = *config.CacheConfig.RevCacheConfig.MaxItemCount
1222 }
1223 if config.CacheConfig.RevCacheConfig.MaxMemoryCountMB != nil {
1224 maxMemoryConfigValue := *config.CacheConfig.RevCacheConfig.MaxMemoryCountMB
1225 if maxMemoryConfigValue != uint32(0) && maxMemoryConfigValue < uint32(50) {
1226 return db.DatabaseContextOptions{}, fmt.Errorf("maximum rev cache memory size cannot be lower than 50 MB")
1227 }
1228 revCacheOptions.MaxBytes = int64(*config.CacheConfig.RevCacheConfig.MaxMemoryCountMB * 1024 * 1024) // Convert MB input to bytes
1229 }

Callers 2

Calls 15

WarnfCtxFunction · 0.92
DefaultCacheOptionsFunction · 0.92
InfofCtxFunction · 0.92
IsEnterpriseEditionFunction · 0.92
PtrFunction · 0.92
ValDefaultFunction · 0.92
CompileFunctionsFunction · 0.92
getJavascriptTimeoutFunction · 0.85
newBaseImportOptionsFunction · 0.85
IsServerlessMethod · 0.80

Tested by 1