You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何启用org.springframework.data.aerospike.config.AerospikeDataSettings的scansEnabled属性

问题原因

spring-data-aerospike 默认禁用了无过滤条件的全表扫描操作,而 findAll() 方法没有指定过滤规则,执行时会触发全库扫描,这类操作容易占用大量集群 IO、CPU 资源,影响线上业务稳定性,因此框架默认关闭了该能力。

解决方案

提供两种可选方案,优先推荐生产环境使用方案2规避全表扫描风险。

方案1:临时开启扫描权限(适合测试/小数据量场景)

有两种常用配置方式:

  • 配置文件配置(Spring Boot 2.4+ 版本适用)
    若使用 application.yml 配置,添加如下内容:
    spring:
      data:
        aerospike:
          scans-enabled: true
    
    若使用 application.properties 配置,添加如下内容:
    spring.data.aerospike.scans-enabled=true
    
  • 代码自定义配置
    手动注册 AerospikeDataSettings Bean 开启扫描:
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.data.aerospike.config.AerospikeDataSettings;
    
    @Configuration
    public class AerospikeCustomConfig {
        @Bean
        public AerospikeDataSettings aerospikeDataSettings() {
            return AerospikeDataSettings.builder()
                    .scansEnabled(true)
                    .build();
        }
    }
    

注意:生产环境开启前必须评估集群数据量级,百万级以上数据的全表扫描大概率会导致集群性能下降,甚至触发节点雪崩。

方案2:优化查询逻辑(推荐生产环境使用)

避免直接调用无过滤条件的 findAll(),根据业务场景调整实现:

  • 若是分页查询需求,调用带分页参数的方法 findAll(Pageable pageable),框架会自动优化为分批拉取,不会触发全表扫描校验。
  • 若确实需要拉取全量数据,改用 Aerospike 原生异步扫描接口,配置扫描限速、并发数参数,避免扫描操作占用过多集群资源。
  • 给常用查询字段创建二级索引,使用带索引字段的过滤条件查询替代全表扫描,性能和稳定性都更高。

内容的提问来源于stack exchange,提问作者dc-coder

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.23 20:36:02