Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(data-service): disable utf8 validation when retrieving metadata compass needs in order to function COMPASS-8517 #6531

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 40 additions & 37 deletions packages/data-service/src/data-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1083,49 +1083,52 @@ class DataServiceImpl extends WithLogContext implements DataService {
try {
const coll = this._collection(ns, 'CRUD');
const collStats = await coll
.aggregate([
{ $collStats: { storageStats: {} } },
{
$group: {
_id: null,
capped: { $first: '$storageStats.capped' },
count: { $sum: '$storageStats.count' },
size: { $sum: { $toDouble: '$storageStats.size' } },
storageSize: {
$sum: { $toDouble: '$storageStats.storageSize' },
},
totalIndexSize: {
$sum: { $toDouble: '$storageStats.totalIndexSize' },
},
freeStorageSize: {
$sum: { $toDouble: '$storageStats.freeStorageSize' },
},
unscaledCollSize: {
$sum: {
$multiply: [
{ $toDouble: '$storageStats.avgObjSize' },
{ $toDouble: '$storageStats.count' },
],
.aggregate(
[
{ $collStats: { storageStats: {} } },
{
$group: {
_id: null,
capped: { $first: '$storageStats.capped' },
count: { $sum: '$storageStats.count' },
size: { $sum: { $toDouble: '$storageStats.size' } },
storageSize: {
$sum: { $toDouble: '$storageStats.storageSize' },
},
totalIndexSize: {
$sum: { $toDouble: '$storageStats.totalIndexSize' },
},
freeStorageSize: {
$sum: { $toDouble: '$storageStats.freeStorageSize' },
},
unscaledCollSize: {
$sum: {
$multiply: [
{ $toDouble: '$storageStats.avgObjSize' },
{ $toDouble: '$storageStats.count' },
],
},
},
nindexes: { $max: '$storageStats.nindexes' },
},
nindexes: { $max: '$storageStats.nindexes' },
},
},
{
$addFields: {
// `avgObjSize` is the average of per-shard `avgObjSize` weighted by `count`
avgObjSize: {
$cond: {
if: { $ne: ['$count', 0] },
then: {
$divide: ['$unscaledCollSize', { $toDouble: '$count' }],
{
$addFields: {
// `avgObjSize` is the average of per-shard `avgObjSize` weighted by `count`
avgObjSize: {
$cond: {
if: { $ne: ['$count', 0] },
then: {
$divide: ['$unscaledCollSize', { $toDouble: '$count' }],
},
else: 0,
},
else: 0,
},
},
},
},
])
],
{ enableUtf8Validation: false }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just added this option which triggered the whole aggregation to be reformatted by prettier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this one here because the user's error log file contained a lot of aggregate failed commands and we have a hunch it might be this one.

)
.toArray();

if (!collStats || collStats[0] === undefined) {
Expand Down Expand Up @@ -1226,7 +1229,7 @@ class DataServiceImpl extends WithLogContext implements DataService {
try {
const cursor = this._database(databaseName, 'CRUD').listCollections(
filter,
{ nameOnly }
{ nameOnly, enableUtf8Validation: false }
lerouxb marked this conversation as resolved.
Show resolved Hide resolved
);
// Iterate instead of using .toArray() so we can emit
// collection info update events as they come in.
Expand Down
2 changes: 1 addition & 1 deletion packages/data-service/src/run-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ export const runCommand: RunCommand = (

return db.command(
{ ...spec },
{ readPreference, ...options }
{ readPreference, enableUtf8Validation: false, ...options }
lerouxb marked this conversation as resolved.
Show resolved Hide resolved
// It's pretty hard to convince TypeScript that we are doing the right thing
// here due to how vague the driver types are hence the `any` assertion
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
Loading