Pageable not working with spring data aerospike

时间:2017-08-04 12:28:41

标签: spring-data aerospike

I am using aerospike spring data

compile 'com.aerospike:spring-data-aerospike:1.0.2.RELEASE'
compile 'com.aerospike:aerospike-client:3.3.4'
compile 'com.aerospike:aerospike-helper-java:1.2'

When am trying to work with pageable am getting all the records instead of just one page with the specific set of records

Page<Account> findByGender(String gender, Pageable pageable);

This method is listed under interface

public interface AccountRepo extends AerospikeRepository<Account, UUID>

And accessing it by passing Gender and pageable

Pageable pageable = new PageRequest(page, pageSize);

1 个答案:

答案 0 :(得分:1)

Aerospike是一个分布式数据库,这意味着扫描和查询将发送到群集中的所有节点。每个节点都与其他节点共享,因此它们不协调返回的顺序或记录。同样,在节点内扫描和查询是跨核心的多线程操作。这是每次结果顺序不同的另一个原因。

分页的解决方法是在客户端缓存完整的结果集,然后浏览它们。在RDBMS中,在服务器端分配内存以对结果进行排序和缓存。在分布式RDBMS中,需要指定一个特定节点,所有结果都从其他节点移动到它,并且必须对其进行缓冲,排序和缓存。 Aerospike的设计理念是不以这种方式浪费服务器资源,而是将该操作的责任转移到应用程序端,让服务器集群以非常低的延迟处理许多请求。

在您的应用程序中,您应该缓冲,排序和缓存结果,并通过此缓存进行分页。您可以使用有限的TTL将这些结果缓存回Aerospike(例如,进入内存中的命名空间)。