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

Extend unique index for rhnpackagechangelogdata table #7531

Merged
merged 7 commits into from
Oct 25, 2023
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
4 changes: 0 additions & 4 deletions python/spacewalk/satellite_tools/reposync.py
Original file line number Diff line number Diff line change
Expand Up @@ -1366,10 +1366,6 @@ def import_package_batch(self, to_process, to_disassociate, is_non_local_repo, b
raise
except Exception as e:
e_message = f'Exception: {e}'
if importer:
e_message += f'\nPackage: {repr(importer)}'
if src_importer:
e_message += f'\nSource package: {repr(src_importer)}'
log2(0, 1, e_message, stream=sys.stderr)
if self.fail:
raise
Expand Down
10 changes: 9 additions & 1 deletion python/spacewalk/server/importlib/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
from spacewalk.common.rhnConfig import CFG
from spacewalk.common.rhnException import rhnFault
from spacewalk.common.rhnLog import log_debug
from spacewalk.satellite_tools import syncLib
from spacewalk.server import rhnSQL, rhnChannel, taskomatic
from .importLib import Diff, Package, IncompletePackage, Erratum, \
AlreadyUploadedError, InvalidPackageError, TransactionError, \
SourcePackage
from .backendLib import TableCollection, sanitizeValue, TableDelete, \
TableUpdate, TableLookup, addHash, TableInsert


sequences = {
'rhnPackageCapability': 'rhn_pkg_capability_id_seq',
'rhnPackage': 'rhn_package_id_seq',
Expand Down Expand Up @@ -984,10 +986,16 @@ def processPackages(self, packages, uploadForce=0, ignoreUploaded=0,
package['header_start'] = -1
package['header_end'] = -1

self.__processObjectCollection__([package, ], 'rhnPackage', tableList,
try:
self.__processObjectCollection__([package, ], 'rhnPackage', tableList,
uploadForce=uploadForce, forceVerify=forceVerify,
ignoreUploaded=ignoreUploaded, severityLimit=1,
transactional=transactional)
except Exception as e:
syncLib.log(0, "Error during processing package %s-%s-%s:%s.%s.\n%s" %
(package['name'], package['version'], package['release'], package['epoch'], package['arch'],
str(e)))
raise

def processErrata(self, errata):
# Insert/update the packages
Expand Down
14 changes: 9 additions & 5 deletions python/spacewalk/server/importlib/packageImport.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,16 +285,20 @@ def _processPackage(self, package):
self.checksums[fchecksumTuple] = None

# Uniquify changelog entries
unique_package_changelog_hash = {}
unique_package_changelog_hash = set()
unique_package_changelog = []
for changelog in package['changelog']:
key = (self._fix_encoding(changelog['name'][:128]), self._fix_encoding(changelog['time']), self._fix_encoding(changelog['text'])[:3000])
changelog_name = self._fix_encoding(changelog['name'][:128])
changelog_time = self._fix_encoding(changelog['time'])
changelog_text = self._fix_encoding(changelog['text'])[:3000]
key = (changelog_name, changelog_time, changelog_text)
if key not in unique_package_changelog_hash:
self.changelog_data[key] = None
changelog['name'] = changelog['name'][:128]
changelog['text'] = changelog['text'][:3000]
changelog['name'] = changelog_name
changelog['text'] = changelog_text
changelog['time'] = changelog_time
unique_package_changelog.append(changelog)
unique_package_changelog_hash[key] = 1
unique_package_changelog_hash.add(key)
package['changelog'] = unique_package_changelog

# fix encoding issues in package summary and description
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add unique index for rhnpackagechangelogdata table
6 changes: 3 additions & 3 deletions schema/spacewalk/common/tables/rhnPackageChangeLogData.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
-- in this software or its documentation.
--


CREATE TABLE rhnPackageChangeLogData
(
id NUMERIC NOT NULL
Expand All @@ -28,8 +27,9 @@ CREATE TABLE rhnPackageChangeLogData

;

CREATE INDEX rhn_pkg_cld_nt_idx
ON rhnPackageChangeLogData (name, time)
CREATE UNIQUE INDEX rhn_pkg_cld_ntt_idx
ON rhnPackageChangeLogData
USING btree(name, digest("text", 'sha512'::text), time)

;

Expand Down
2 changes: 2 additions & 0 deletions schema/spacewalk/postgres/start.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ create temporary table store_searchpath as select setting from pg_settings where

update pg_settings set setting = (select setting from store_searchpath) where name = 'search_path';
drop table store_searchpath;

CREATE EXTENSION pgcrypto;
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
create or replace function remove_duplicate_changelogdata()
returns void as
$$
declare original record;
declare duplicate record;
begin
for original in select min(id) as id
from rhnpackagechangelogdata
group by name, text, time
having count(*) > 1 loop
for duplicate in select data2.id
from rhnpackagechangelogdata data1, rhnpackagechangelogdata data2
where data1.name = data2.name
and data1.text = data2.text
and data1.time = data2.time
and data1.id != data2.id
and data1.id = original.id loop
update rhnpackagechangelogrec
set changelog_data_id = original.id
where changelog_data_id = duplicate.id;
delete from rhnpackagechangelogdata
where id = duplicate.id;
end loop;
end loop;
end;
$$ language plpgsql;

select remove_duplicate_changelogdata();
drop function remove_duplicate_changelogdata();

drop index if exists rhn_pkg_cld_nt_idx;
drop index if exists rhn_pkg_cld_ntt_idx;

create extension if not exists pgcrypto;
create unique index concurrently rhn_pkg_cld_ntt_idx
on "rhnpackagechangelogdata"
using btree(name, digest("text", 'sha512'::text), "time");