Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion sync/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Library for leveraging the power of Sync"""
__version__ = "1.0.2"
__version__ = "1.0.3"

TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
39 changes: 25 additions & 14 deletions sync/awsdatabricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
from pathlib import Path
from time import sleep
from typing import List, Tuple
from typing import Generator, List, Tuple
from urllib.parse import urlparse

import boto3 as boto
Expand Down Expand Up @@ -481,28 +481,39 @@ def _get_ebs_volumes_for_instances(
) -> List[dict]:
"""Get all ebs volumes associated with a list of instance reservations"""

def get_chunk(instance_ids: list[str], chunk_size: int) -> Generator[list[str]]:
"""
Splits the instance_ids list into chunks of size determined by chunk_size.
This function exists to respect thresholds required by the call to
ec2_client.describe_volumes below.
"""
for idx in range(0, len(instance_ids), chunk_size):
yield instance_ids[idx : idx + chunk_size]

instance_ids = []
if instances:
for instance in instances:
instance_ids.append(instance.get("InstanceId"))

volumes = []
if instance_ids:
filters = [
{"Name": "tag:Vendor", "Values": ["Databricks"]},
{"Name": "attachment.instance-id", "Values": instance_ids},
]

response = ec2_client.describe_volumes(Filters=filters)
volumes = response.get("Volumes", [])
next_token = response.get("NextToken")
MAX_CHUNK_SIZE = 199

while next_token:
response = ec2_client.describe_volumes(Filters=filters, NextToken=next_token)
volumes += response.get("Volumes", [])
if instance_ids:
for chunk in get_chunk(instance_ids, MAX_CHUNK_SIZE):
filters = [
{"Name": "tag:Vendor", "Values": ["Databricks"]},
{"Name": "attachment.instance-id", "Values": chunk},
]

response = ec2_client.describe_volumes(Filters=filters)
volumes = response.get("Volumes", [])
next_token = response.get("NextToken")

while next_token:
response = ec2_client.describe_volumes(Filters=filters, NextToken=next_token)
volumes += response.get("Volumes", [])
next_token = response.get("NextToken")

Comment on lines +512 to +516
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you had a chance to test this out on a big cluster yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I tested this out by kicking off a big job with 300 .large instances and then wrote a local scipt to call describe_volumes() on that cluster_id while the cluster was running and it worked fine (also worked fine for a cluster with 10 instances)

num_vol = len(volumes)
logger.info(f"Identified {num_vol} ebs volumes in cluster")

return volumes