-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Spark ingestion to use Jedis instead of Spark Redis (#107)
* replace spark redis with jedis library * unified cluster and single node interface Signed-off-by: Khor Shu Heng <khor.heng@go-jek.com> * Use intersect type to simplified common interface Signed-off-by: Khor Shu Heng <khor.heng@go-jek.com> * handle case where config is not set Signed-off-by: Khor Shu Heng <khor.heng@go-jek.com> * modify doc string Signed-off-by: Khor Shu Heng <khor.heng@go-jek.com>
- Loading branch information
1 parent
b2e7426
commit 0f4e27c
Showing
11 changed files
with
199 additions
and
90 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
41 changes: 41 additions & 0 deletions
41
spark/ingestion/src/main/scala/feast/ingestion/stores/redis/ClusterPipelineProvider.scala
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright 2018-2022 The Feast Authors | ||
* | ||
* Licensed 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 | ||
* | ||
* https://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 feast.ingestion.stores.redis | ||
|
||
import redis.clients.jedis.{ClusterPipeline, DefaultJedisClientConfig, HostAndPort} | ||
import redis.clients.jedis.providers.ClusterConnectionProvider | ||
|
||
import scala.collection.JavaConverters._ | ||
|
||
/** | ||
* Provide pipeline for Redis cluster. | ||
*/ | ||
case class ClusterPipelineProvider(endpoint: RedisEndpoint) extends PipelineProvider { | ||
|
||
val nodes = Set(new HostAndPort(endpoint.host, endpoint.port)).asJava | ||
val DEFAULT_CLIENT_CONFIG = DefaultJedisClientConfig | ||
.builder() | ||
.password(endpoint.password) | ||
.build() | ||
val provider = new ClusterConnectionProvider(nodes, DEFAULT_CLIENT_CONFIG) | ||
|
||
/** | ||
* @return a cluster pipeline | ||
*/ | ||
override def pipeline(): UnifiedPipeline = new ClusterPipeline(provider) | ||
|
||
} |
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
34 changes: 34 additions & 0 deletions
34
spark/ingestion/src/main/scala/feast/ingestion/stores/redis/PipelineProvider.scala
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright 2018-2022 The Feast Authors | ||
* | ||
* Licensed 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 | ||
* | ||
* https://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 feast.ingestion.stores.redis | ||
|
||
import redis.clients.jedis.commands.PipelineBinaryCommands | ||
|
||
import java.io.Closeable | ||
|
||
/** | ||
* Provide either a pipeline or cluster pipeline to read and write data into Redis. | ||
*/ | ||
trait PipelineProvider { | ||
|
||
type UnifiedPipeline = PipelineBinaryCommands with Closeable | ||
|
||
/** | ||
* @return an interface for executing pipeline commands | ||
*/ | ||
def pipeline(): UnifiedPipeline | ||
} |
19 changes: 19 additions & 0 deletions
19
spark/ingestion/src/main/scala/feast/ingestion/stores/redis/RedisEndpoint.scala
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright 2018-2022 The Feast Authors | ||
* | ||
* Licensed 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 | ||
* | ||
* https://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 feast.ingestion.stores.redis | ||
|
||
case class RedisEndpoint(host: String, port: Int, password: String) |
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
31 changes: 31 additions & 0 deletions
31
spark/ingestion/src/main/scala/feast/ingestion/stores/redis/SingleNodePipelineProvider.scala
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright 2018-2022 The Feast Authors | ||
* | ||
* Licensed 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 | ||
* | ||
* https://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 feast.ingestion.stores.redis | ||
|
||
import redis.clients.jedis.Jedis | ||
|
||
/** | ||
* Provide pipeline for single node Redis. | ||
*/ | ||
case class SingleNodePipelineProvider(jedis: Jedis) extends PipelineProvider { | ||
|
||
/** | ||
* @return a single node redis pipeline | ||
*/ | ||
override def pipeline(): UnifiedPipeline = jedis.pipelined() | ||
|
||
} |
Oops, something went wrong.