From 9b63f84ff93f571495327efe998553327252727d Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 18 Sep 2014 08:36:22 -0700 Subject: [PATCH] Generate reasonable expected schemata for Cache tables Summary: Ref T1191. Notable: - Rename `blob` to `bytes` for clarity. - Introduce raw schema specs. Test Plan: See screenshots. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T1191 Differential Revision: https://secure.phabricator.com/D10501 --- src/__phutil_library_map__.php | 2 ++ .../storage/PhabricatorCacheSchemaSpec.php | 31 ++++++++++++++++ .../cache/storage/PhabricatorMarkupCache.php | 8 +++++ .../schema/PhabricatorConfigColumnSchema.php | 7 ++++ .../schema/PhabricatorConfigSchemaSpec.php | 35 +++++++++++++++---- src/infrastructure/storage/lisk/LiskDAO.php | 2 +- 6 files changed, 78 insertions(+), 7 deletions(-) create mode 100644 src/applications/cache/storage/PhabricatorCacheSchemaSpec.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 25ba33868a..044980e5b4 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1277,6 +1277,7 @@ phutil_register_library_map(array( 'PhabricatorCacheManagementPurgeWorkflow' => 'applications/cache/management/PhabricatorCacheManagementPurgeWorkflow.php', 'PhabricatorCacheManagementWorkflow' => 'applications/cache/management/PhabricatorCacheManagementWorkflow.php', 'PhabricatorCacheMarkupGarbageCollector' => 'applications/cache/garbagecollector/PhabricatorCacheMarkupGarbageCollector.php', + 'PhabricatorCacheSchemaSpec' => 'applications/cache/storage/PhabricatorCacheSchemaSpec.php', 'PhabricatorCacheTTLGarbageCollector' => 'applications/cache/garbagecollector/PhabricatorCacheTTLGarbageCollector.php', 'PhabricatorCaches' => 'applications/cache/PhabricatorCaches.php', 'PhabricatorCalendarApplication' => 'applications/calendar/application/PhabricatorCalendarApplication.php', @@ -4161,6 +4162,7 @@ phutil_register_library_map(array( 'PhabricatorCacheManagementPurgeWorkflow' => 'PhabricatorCacheManagementWorkflow', 'PhabricatorCacheManagementWorkflow' => 'PhabricatorManagementWorkflow', 'PhabricatorCacheMarkupGarbageCollector' => 'PhabricatorGarbageCollector', + 'PhabricatorCacheSchemaSpec' => 'PhabricatorConfigSchemaSpec', 'PhabricatorCacheTTLGarbageCollector' => 'PhabricatorGarbageCollector', 'PhabricatorCalendarApplication' => 'PhabricatorApplication', 'PhabricatorCalendarBrowseController' => 'PhabricatorCalendarController', diff --git a/src/applications/cache/storage/PhabricatorCacheSchemaSpec.php b/src/applications/cache/storage/PhabricatorCacheSchemaSpec.php new file mode 100644 index 0000000000..ed481a25df --- /dev/null +++ b/src/applications/cache/storage/PhabricatorCacheSchemaSpec.php @@ -0,0 +1,31 @@ +buildLiskSchemata('PhabricatorCacheDAO'); + + $this->buildRawSchema( + 'cache', + id(new PhabricatorKeyValueDatabaseCache())->getTableName(), + array( + 'id' => 'id64', + 'cacheKeyHash' => 'bytes12', + 'cacheKey' => 'text128', + 'cacheFormat' => 'text16', + 'cacheData' => 'bytes', + 'cacheCreated' => 'epoch', + 'cacheExpires' => 'epoch?', + ), + array( + 'PRIMARY' => array( + 'columns' => array('id'), + ), + 'key_cacheKeyHash' => array( + 'columns' => array('cacheKeyHash'), + ), + )); + + } + +} diff --git a/src/applications/cache/storage/PhabricatorMarkupCache.php b/src/applications/cache/storage/PhabricatorMarkupCache.php index 6ce0593bb2..a67e4d63ff 100644 --- a/src/applications/cache/storage/PhabricatorMarkupCache.php +++ b/src/applications/cache/storage/PhabricatorMarkupCache.php @@ -15,6 +15,14 @@ final class PhabricatorMarkupCache extends PhabricatorCacheDAO { self::CONFIG_BINARY => array( 'cacheData' => true, ), + self::CONFIG_COLUMN_SCHEMA => array( + 'cacheKey' => 'text128', + ), + self::CONFIG_KEY_SCHEMA => array( + 'cacheKey' => array( + 'columns' => array('cacheKey'), + ), + ), ) + parent::getConfiguration(); } diff --git a/src/applications/config/schema/PhabricatorConfigColumnSchema.php b/src/applications/config/schema/PhabricatorConfigColumnSchema.php index eb5e909338..7bad159afa 100644 --- a/src/applications/config/schema/PhabricatorConfigColumnSchema.php +++ b/src/applications/config/schema/PhabricatorConfigColumnSchema.php @@ -67,6 +67,13 @@ final class PhabricatorConfigColumnSchema return ((int)$matches[1]) * 4; } + $matches = null; + if (preg_match('/^char\((\d+)\)$/', $type, $matches)) { + // We use char() only for fixed-length binary data, so its size + // is always the column size. + return ((int)$matches[1]); + } + switch ($type) { case 'int(10) unsigned': return 4; diff --git a/src/applications/config/schema/PhabricatorConfigSchemaSpec.php b/src/applications/config/schema/PhabricatorConfigSchemaSpec.php index 62a0ec6a83..f534c0bf26 100644 --- a/src/applications/config/schema/PhabricatorConfigSchemaSpec.php +++ b/src/applications/config/schema/PhabricatorConfigSchemaSpec.php @@ -57,12 +57,23 @@ abstract class PhabricatorConfigSchemaSpec extends Phobject { } private function buildLiskObjectSchema(PhabricatorLiskDAO $object) { - $database = $this->getDatabase($object->getApplicationName()); + $this->buildRawSchema( + $object->getApplicationName(), + $object->getTableName(), + $object->getSchemaColumns(), + $object->getSchemaKeys()); + } - $table = $this->newTable($object->getTableName()); + protected function buildRawSchema( + $database_name, + $table_name, + array $columns, + array $keys) { + $database = $this->getDatabase($database_name); - $cols = $object->getSchemaColumns(); - foreach ($cols as $name => $type) { + $table = $this->newTable($table_name); + + foreach ($columns as $name => $type) { $details = $this->getDetailsForDataType($type); list($column_type, $charset, $collation, $nullable) = $details; @@ -76,7 +87,6 @@ abstract class PhabricatorConfigSchemaSpec extends Phobject { $table->addColumn($column); } - $keys = $object->getSchemaKeys(); foreach ($keys as $key_name => $key_spec) { $key = $this->newKey($key_name) ->setColumnNames(idx($key_spec, 'columns', array())); @@ -147,13 +157,21 @@ abstract class PhabricatorConfigSchemaSpec extends Phobject { case 'uint32': $column_type = 'int(10) unsigned'; break; + case 'id64': + $column_type = 'bigint(20) unsigned'; + break; case 'phid': case 'policy'; $column_type = 'varchar(64)'; $charset = 'binary'; $collation = 'binary'; break; - case 'blob': + case 'bytes12': + $column_type = 'char(12)'; + $charset = 'binary'; + $collation = 'binary'; + break; + case 'bytes': $column_type = 'longblob'; $charset = 'binary'; $collation = 'binary'; @@ -173,6 +191,11 @@ abstract class PhabricatorConfigSchemaSpec extends Phobject { $charset = $this->getUTF8Charset(); $collation = $this->getUTF8Collation(); break; + case 'text16': + $column_type = 'varchar(16)'; + $charset = $this->getUTF8Charset(); + $collation = $this->getUTF8Collation(); + break; case 'text12': $column_type = 'varchar(12)'; $charset = $this->getUTF8Charset(); diff --git a/src/infrastructure/storage/lisk/LiskDAO.php b/src/infrastructure/storage/lisk/LiskDAO.php index e7d2989430..c12e3fc027 100644 --- a/src/infrastructure/storage/lisk/LiskDAO.php +++ b/src/infrastructure/storage/lisk/LiskDAO.php @@ -1734,7 +1734,7 @@ abstract class LiskDAO { $serialization_map = array( self::SERIALIZATION_JSON => 'text', - self::SERIALIZATION_PHP => 'blob', + self::SERIALIZATION_PHP => 'bytes', ); $builtin = array(