-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
GridQueryIndexing.java
245 lines (223 loc) · 8.65 KB
/
GridQueryIndexing.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ignite.internal.processors.query;
import java.util.Collection;
import java.util.List;
import javax.cache.Cache;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.cache.query.QueryCursor;
import org.apache.ignite.cache.query.SqlFieldsQuery;
import org.apache.ignite.cache.query.SqlQuery;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
import org.apache.ignite.internal.processors.cache.CacheObject;
import org.apache.ignite.internal.processors.cache.GridCacheContext;
import org.apache.ignite.internal.processors.cache.query.GridCacheTwoStepQuery;
import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
import org.apache.ignite.internal.util.GridSpinBusyLock;
import org.apache.ignite.internal.util.lang.GridCloseableIterator;
import org.apache.ignite.lang.IgniteBiTuple;
import org.apache.ignite.lang.IgniteFuture;
import org.apache.ignite.spi.indexing.IndexingQueryFilter;
import org.jetbrains.annotations.Nullable;
/**
* Abstraction for internal indexing implementation.
*/
public interface GridQueryIndexing {
/**
* Starts indexing.
*
* @param ctx Context.
* @param busyLock Busy lock.
* @throws IgniteCheckedException If failed.
*/
public void start(GridKernalContext ctx, GridSpinBusyLock busyLock) throws IgniteCheckedException;
/**
* Stops indexing.
*
* @throws IgniteCheckedException If failed.
*/
public void stop() throws IgniteCheckedException;
/**
* Runs two step query.
*
* @param cctx Cache context.
* @param qry Query.
* @param keepCacheObjects If {@code true}, cache objects representation will be preserved.
* @return Cursor.
*/
public Iterable<List<?>> queryTwoStep(GridCacheContext<?,?> cctx, GridCacheTwoStepQuery qry,
boolean keepCacheObjects);
/**
* Parses SQL query into two step query and executes it.
*
* @param cctx Cache context.
* @param qry Query.
* @return Cursor.
*/
public QueryCursor<List<?>> queryTwoStep(GridCacheContext<?,?> cctx, SqlFieldsQuery qry);
/**
* Parses SQL query into two step query and executes it.
*
* @param cctx Cache context.
* @param qry Query.
* @return Cursor.
*/
public <K,V> QueryCursor<Cache.Entry<K,V>> queryTwoStep(GridCacheContext<?,?> cctx, SqlQuery qry);
/**
* Queries individual fields (generally used by JDBC drivers).
*
* @param spaceName Space name.
* @param qry Query.
* @param params Query parameters.
* @param filters Space name and key filters.
* @return Query result.
* @throws IgniteCheckedException If failed.
*/
public GridQueryFieldsResult queryFields(@Nullable String spaceName, String qry,
Collection<Object> params, IndexingQueryFilter filters) throws IgniteCheckedException;
/**
* Executes regular query.
*
* @param spaceName Space name.
* @param qry Query.
* @param params Query parameters.
* @param type Query return type.
* @param filters Space name and key filters.
* @return Queried rows.
* @throws IgniteCheckedException If failed.
*/
public <K, V> GridCloseableIterator<IgniteBiTuple<K, V>> query(@Nullable String spaceName, String qry,
Collection<Object> params, GridQueryTypeDescriptor type, IndexingQueryFilter filters) throws IgniteCheckedException;
/**
* Executes text query.
*
* @param spaceName Space name.
* @param qry Text query.
* @param type Query return type.
* @param filters Space name and key filter.
* @return Queried rows.
* @throws IgniteCheckedException If failed.
*/
public <K, V> GridCloseableIterator<IgniteBiTuple<K, V>> queryText(@Nullable String spaceName, String qry,
GridQueryTypeDescriptor type, IndexingQueryFilter filters) throws IgniteCheckedException;
/**
* Gets size of index for given type or -1 if it is a unknown type.
*
* @param spaceName Space name.
* @param desc Type descriptor.
* @param filters Filters.
* @return Objects number.
* @throws IgniteCheckedException If failed.
*/
public long size(@Nullable String spaceName, GridQueryTypeDescriptor desc, IndexingQueryFilter filters)
throws IgniteCheckedException;
/**
* Registers cache.
*
* @param ccfg Cache configuration.
* @throws IgniteCheckedException If failed.
*/
public void registerCache(CacheConfiguration<?,?> ccfg) throws IgniteCheckedException;
/**
* Deregisters cache.
*
* @param ccfg Cache configuration.
* @throws IgniteCheckedException If failed to drop cache schema.
*/
public void unregisterCache(CacheConfiguration<?, ?> ccfg) throws IgniteCheckedException;
/**
* Registers type if it was not known before or updates it otherwise.
*
* @param spaceName Space name.
* @param desc Type descriptor.
* @throws IgniteCheckedException If failed.
* @return {@code True} if type was registered, {@code false} if for some reason it was rejected.
*/
public boolean registerType(@Nullable String spaceName, GridQueryTypeDescriptor desc) throws IgniteCheckedException;
/**
* Unregisters type and removes all corresponding data.
*
* @param spaceName Space name.
* @param type Type descriptor.
* @throws IgniteCheckedException If failed.
*/
public void unregisterType(@Nullable String spaceName, GridQueryTypeDescriptor type) throws IgniteCheckedException;
/**
* Updates index. Note that key is unique for space, so if space contains multiple indexes
* the key should be removed from indexes other than one being updated.
*
* @param spaceName Space name.
* @param type Value type.
* @param key Key.
* @param val Value.
* @param ver Version.
* @param expirationTime Expiration time or 0 if never expires.
* @throws IgniteCheckedException If failed.
*/
public void store(@Nullable String spaceName, GridQueryTypeDescriptor type, CacheObject key, CacheObject val,
GridCacheVersion ver, long expirationTime) throws IgniteCheckedException;
/**
* Removes index entry by key.
*
* @param spaceName Space name.
* @param key Key.
* @param val Value.
* @throws IgniteCheckedException If failed.
*/
public void remove(@Nullable String spaceName, CacheObject key, CacheObject val, GridCacheVersion ver) throws IgniteCheckedException;
/**
* Will be called when entry with given key is swapped.
*
* @param spaceName Space name.
* @param key Key.
* @throws IgniteCheckedException If failed.
*/
public void onSwap(@Nullable String spaceName, CacheObject key) throws IgniteCheckedException;
/**
* Will be called when entry with given key is unswapped.
*
* @param spaceName Space name.
* @param key Key.
* @param val Value.
* @throws IgniteCheckedException If failed.
*/
public void onUnswap(@Nullable String spaceName, CacheObject key, CacheObject val) throws IgniteCheckedException;
/**
* Rebuilds all indexes of given type.
*
* @param spaceName Space name.
* @param type Type descriptor.
*/
public void rebuildIndexes(@Nullable String spaceName, GridQueryTypeDescriptor type);
/**
* Returns backup filter.
*
* @param caches List of caches.
* @param topVer Topology version.
* @param parts Partitions.
* @return Backup filter.
*/
public IndexingQueryFilter backupFilter(List<String> caches, AffinityTopologyVersion topVer, int[] parts);
/**
* Client disconnected callback.
*
* @param reconnectFut Reconnect future.
*/
public void onDisconnected(IgniteFuture<?> reconnectFut);
}