<commit_before>package org.sagebionetworks.repo.manager.migration;

import java.io.IOException;
import java.util.List;

import org.sagebionetworks.StackConfiguration;
import org.sagebionetworks.repo.model.dao.table.TableRowTruthDAO;
import org.sagebionetworks.repo.model.dbo.DatabaseObject;
import org.sagebionetworks.repo.model.jdo.KeyFactory;
import org.sagebionetworks.repo.model.migration.MigrationType;
import org.sagebionetworks.table.cluster.ConnectionFactory;
import org.sagebionetworks.table.cluster.TableIndexDAO;
import org.springframework.beans.factory.annotation.Autowired;

public class TableCacheInvalidationMigrationListener implements MigrationTypeListener {

	@Autowired
	TableRowTruthDAO tableRowTruthDAO;

	@Autowired
	ConnectionFactory tableConnectionFactory;

	@Override
	public <D extends DatabaseObject<?>> void afterCreateOrUpdate(MigrationType type, List<D> delta) {
		// nothing here
	}

	@Override
	public void beforeDeleteBatch(MigrationType type, List<Long> idsToDelete) {
		// we only deal with table change sets here
		if (type != MigrationType.TABLE_CHANGE) {
			return;
		}

		if (!StackConfiguration.singleton().getTableEnabled()) {
			return;
		}

		try {
			// the idsToDelete is a list of table ids for this type
			for (Long tableId : idsToDelete) {
				String tableIdString = KeyFactory.keyToString(tableId);
				TableIndexDAO indexDAO = tableConnectionFactory.getConnection(tableIdString);
				tableRowTruthDAO.removeCaches(tableId);
				indexDAO.deleteTable(tableIdString);
				indexDAO.deleteStatusTable(tableIdString);
			}
		} catch (IOException e) {
			// we want the migration to fail if any of the caches cannot be cleared
			throw new RuntimeException(e.getMessage(), e);
		}
	}
}<commit_msg>adding some logging for debugging<commit_after>package org.sagebionetworks.repo.manager.migration;

import java.io.IOException;
import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.sagebionetworks.S3PropertyFileLoader;
import org.sagebionetworks.StackConfiguration;
import org.sagebionetworks.repo.model.dao.table.TableRowTruthDAO;
import org.sagebionetworks.repo.model.dbo.DatabaseObject;
import org.sagebionetworks.repo.model.jdo.KeyFactory;
import org.sagebionetworks.repo.model.migration.MigrationType;
import org.sagebionetworks.table.cluster.ConnectionFactory;
import org.sagebionetworks.table.cluster.TableIndexDAO;
import org.springframework.beans.factory.annotation.Autowired;

public class TableCacheInvalidationMigrationListener implements MigrationTypeListener {

	private static final Logger log = LogManager.getLogger(TableCacheInvalidationMigrationListener.class);

	@Autowired
	TableRowTruthDAO tableRowTruthDAO;

	@Autowired
	ConnectionFactory tableConnectionFactory;

	@Override
	public <D extends DatabaseObject<?>> void afterCreateOrUpdate(MigrationType type, List<D> delta) {
		// nothing here
	}

	@Override
	public void beforeDeleteBatch(MigrationType type, List<Long> idsToDelete) {
		// we only deal with table change sets here
		if (type != MigrationType.TABLE_CHANGE) {
			return;
		}

		if (!StackConfiguration.singleton().getTableEnabled()) {
			return;
		}

		try {
			// the idsToDelete is a list of table ids for this type
			for (Long tableId : idsToDelete) {
				log.info("Deleting table " + tableId + " from index due to migration");
				String tableIdString = KeyFactory.keyToString(tableId);
				TableIndexDAO indexDAO = tableConnectionFactory.getConnection(tableIdString);
				tableRowTruthDAO.removeCaches(tableId);
				indexDAO.deleteTable(tableIdString);
				indexDAO.deleteStatusTable(tableIdString);
			}
		} catch (IOException e) {
			// we want the migration to fail if any of the caches cannot be cleared
			throw new RuntimeException(e.getMessage(), e);
		}
	}
}
{'fraction_non_alphanumeric': 0.08778825995807128, 'fraction_numerical': 0.0007861635220125787, 'mean_word_length': 5.37228714524207, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4051057', 'n_tokens_mistral': 1245, 'n_tokens_neox': 1173, 'n_words': 252}