Handling Collection Errors in HA Clusters
TLDR Mischa was encountering random collection existence errors when updating schemas in a HA cluster. Jason suggested waiting between deletions and recreations or using an alias for zero downtime switches.
Sep 18, 2023 (2 weeks ago)
Mischa
05:21 PMexport const recreateCollection = async (schema: CollectionCreateSchema) => {
const client = await getTypesenseAdminClient()
if (await collectionExists(client, schema)) {
(`Deleting collection ${schema.name}`)
await client.collections(schema.name).delete()
}
(`Creating collection ${schema.name}`)
await client.collections().create(schema)
}
"httpStatus":409,"stack":["ObjectAlreadyExists: Request failed with HTTP code 409 | Server said: A collection with name
xxxx already exists.
Mischa
05:21 PMconst collectionExists = async (client: Client, schema: CollectionCreateSchema) => {
try {
await client.collections(schema.name).retrieve()
return true
} catch (e) {
if ((e as TypesenseError).httpStatus === 404) {
return false
} else {
throw e
}
}
}
Mischa
05:22 PMJason
07:38 PMI'd recommend giving a few second between deleting and trying to recreate a collection with the same name.
Jason
07:40 PMor use an alias: https://typesense.org/docs/0.25.1/api/collections.html#using-an-alias
Sep 20, 2023 (1 week ago)
Mischa
04:21 AMMischa
04:22 AMJason
04:25 AMTypesense
Indexed 2786 threads (79% resolved)
Similar Threads
Issues with Duplicate Entries in New Collections
Ivan reported an issue wherein duplicate entries appear in his database collection. This occurs sporadically when he deletes a collection, creates a new one with the same name, and adds the same entries. Kishore Nallan identified this as a race condition, suggesting a larger timeout value to avoid premature disconnection. Unable to increase the timeout, Ivan instead reduced his import chunks to 500 entries, which successfully eliminated the error.
Issue with Embedding Error in Version 0.25.0.rc63
Bill reported a bug in version 0.25.0.rc63 regarding a problem with updating or emplacing a document and receiving an embedding error. This was resolved in version 0.25.0.rc65, but further discussion ensued regarding the function of 'index' in the update feature.
Issue with "Search Firestore with Typesense" Extension
Rajbek had an issue synchronizing data between Firestore and Typesense collection. Jason helped diagnose the issue and the problem was resolved by Rajbek increasing the memory allocation of the specific cloud function.
Discussing Firestore Extension and Collection Schema in Typesense
Loic asks about settings in Firestore Extension and experiences issues with the collection schema in Typesense. Discussion with Jason is ongoing.
Issue with Query Expectations on Typesense Search
Sean was having an issue with their search query on Typesense. Kishore Nallan suggested adjusting the 'drop_tokens_threshold' parameter. After making the adjustment, Sean found an issue with the order of the results, which was resolved by updating Typesense version.