Skip to content

Commit

Permalink
[ENH] Compaction service setup (#1945)
Browse files Browse the repository at this point in the history
## Description of changes

*Summarize the changes made by this PR.*
 - Improvements & Bug fixes
	 - ...
 - New functionality
	 - This PR adds the necessary artifacts to setup compaction service.

## Test plan
*How are these changes tested?*

- [ ] Tests pass locally with `pytest` for python, `yarn test` for js,
`cargo test` for rust

## Documentation Changes
*Are all docstrings for user-facing APIs updated if required? Do we need
to make documentation changes in the [docs
repository](https://github.com/chroma-core/docs)?*
  • Loading branch information
Ishiihara authored Mar 29, 2024
1 parent 6af795b commit b6e86a6
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 10 deletions.
16 changes: 14 additions & 2 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,16 @@ docker_build(
'local:query-service',
'.',
only=["rust/", "idl/", "Cargo.toml", "Cargo.lock"],
dockerfile='./rust/worker/Dockerfile'
dockerfile='./rust/worker/Dockerfile',
target='query_service'
)

docker_build(
'local:compaction-service',
'.',
only=["rust/", "idl/", "Cargo.toml", "Cargo.lock"],
dockerfile='./rust/worker/Dockerfile',
target='compaction_service'
)

k8s_yaml(
Expand Down Expand Up @@ -82,6 +91,8 @@ k8s_resource(
'compaction-service-memberlist-readerwriter:ClusterRole',
'compaction-service-compaction-service-memberlist-binding:clusterrolebinding',
'compaction-service-memberlist-readerwriter-binding:clusterrolebinding',
'compaction-service-serviceaccount:serviceaccount',
'compaction-service-serviceaccount-rolebinding:RoleBinding',

'test-memberlist:MemberList',
'test-memberlist-reader:ClusterRole',
Expand All @@ -99,7 +110,8 @@ k8s_resource('sysdb-migration', resource_deps=['postgres', 'namespace'], labels=
k8s_resource('logservice', resource_deps=['sysdb-migration'], labels=["chroma"], port_forwards='50052:50051')
k8s_resource('sysdb', resource_deps=['pulsar', 'sysdb-migration'], labels=["chroma"], port_forwards='50051:50051')
k8s_resource('frontend-service', resource_deps=['pulsar', 'sysdb', 'logservice'],labels=["chroma"], port_forwards='8000:8000')
k8s_resource('query-service', resource_deps=['sysdb', 'pulsar'], labels=["chroma"])
k8s_resource('query-service', resource_deps=['sysdb'], labels=["chroma"])
k8s_resource('compaction-service', resource_deps=['sysdb'], labels=["chroma"])

# I have no idea why these need their own lines but the others don't.
k8s_resource(objects=['query-service:service'], new_name='query-service-service', resource_deps=['query-service'], labels=["chroma"])
Expand Down
64 changes: 64 additions & 0 deletions k8s/distributed-chroma/templates/compaction-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: compaction-service
namespace: {{ .Values.namespace }}
spec:
replicas: 1
selector:
matchLabels:
app: compaction-service
template:
metadata:
labels:
app: compaction-service
member-type: compaction-service
spec:
serviceAccountName: compaction-service-serviceaccount
containers:
- name: compaction-service
image: "{{ .Values.compactionService.image.repository }}:{{ .Values.compactionService.image.tag }}"
imagePullPolicy: IfNotPresent
ports:
- containerPort: 50051
env:
- name: CHROMA_compaction-service__MY_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
topologySpreadConstraints:
- maxSkew: 1
topologyKey: "kubernetes.io/hostname"
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
member-type: compaction-service
volumes:
- name: chroma
emptyDir: {}

---

apiVersion: v1
kind: ServiceAccount
metadata:
name: compaction-service-serviceaccount
namespace: {{ .Values.namespace }}

---

apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: compaction-service-serviceaccount-rolebinding
namespace: {{ .Values.namespace }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: pod-watcher
subjects:
- kind: ServiceAccount
name: compaction-service-serviceaccount
namespace: {{ .Values.namespace }}

---
5 changes: 5 additions & 0 deletions k8s/distributed-chroma/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ queryService:
repository: 'local'
tag: 'query-service'

compactionService:
image:
repository: 'local'
tag: 'compaction-service'

sysdbMigration:
image:
repository: 'local'
Expand Down
4 changes: 4 additions & 0 deletions rust/worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ edition = "2021"
name = "query_service"
path = "src/bin/query_service.rs"

[[bin]]
name = "compaction_service"
path = "src/bin/compaction_service.rs"

[dependencies]
tonic = "0.10"
prost = "0.12"
Expand Down
33 changes: 27 additions & 6 deletions rust/worker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,41 @@ RUN curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v25.1
&& unzip -o $PROTOC_ZIP -d /usr/local 'include/*' \
&& rm -f $PROTOC_ZIP

FROM builder as query_service_builder
# We need to replace the query node's real main() with a dummy at the expected location.
RUN mkdir -p rust/worker/src/bin/ && echo "fn main() {}" > rust/worker/src/bin/query_service.rs
RUN if [ "$RELEASE_MODE" = "1" ]; then cargo build --release; else cargo build; fi
RUN if [ "$RELEASE_MODE" = "1" ]; then cargo build --bin query_service --release; else cargo build --bin query_service; fi
RUN rm -rf rust/

COPY rust/ rust/
RUN touch rust/worker/src/bin/query_service.rs
RUN if [ "$RELEASE_MODE" = "1" ]; then cargo build --release; else cargo build; fi
RUN if [ "$RELEASE_MODE" = "1" ]; then cargo build --bin query_service --release; else cargo build --bin query_service; fi
RUN if [ "$RELEASE_MODE" = "1" ]; then mv target/release/query_service .; else mv target/debug/query_service .; fi

FROM debian:bookworm-slim
FROM debian:bookworm-slim as query_service

COPY --from=builder /chroma/query_service .
COPY --from=builder /chroma/rust/worker/chroma_config.yaml .
COPY --from=query_service_builder /chroma/query_service .
COPY --from=query_service_builder /chroma/rust/worker/chroma_config.yaml .
RUN apt-get update && apt-get install -y libssl-dev

ENTRYPOINT [ "./query_service" ]
ENTRYPOINT [ "./query_service" ]

FROM builder as compaction_service_builder

# We need to replace the compaction node's real main() with a dummy at the expected location.
RUN mkdir -p rust/worker/src/bin/ && echo "fn main() {}" > rust/worker/src/bin/compaction_service.rs
RUN if [ "$RELEASE_MODE" = "1" ]; then cargo build --bin compaction_service --release; else cargo build --bin compaction_service; fi
RUN rm -rf rust/

COPY rust/ rust/
RUN touch rust/worker/src/bin/compaction_service.rs
RUN if [ "$RELEASE_MODE" = "1" ]; then cargo build --bin compaction_service --release; else cargo build --bin compaction_service; fi
RUN if [ "$RELEASE_MODE" = "1" ]; then mv target/release/compaction_service .; else mv target/debug/compaction_service .; fi

FROM debian:bookworm-slim as compaction_service

COPY --from=compaction_service_builder /chroma/compaction_service .
COPY --from=compaction_service_builder /chroma/rust/worker/chroma_config.yaml .
RUN apt-get update && apt-get install -y libssl-dev

ENTRYPOINT [ "./compaction_service" ]
7 changes: 5 additions & 2 deletions rust/worker/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Readme

This folder houses the Rust code for the query and compactor nodes. It is a standard rust crate managed using cargo.

### Testing

`cargo test`

### Building
`cargo build`

`cargo build`

### Rust version
Use rust 1.74.0 or greater.

Use rust 1.74.0 or greater.

0 comments on commit b6e86a6

Please sign in to comment.