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

How to get the current shard for a table #271

Open
jacebenson opened this issue Oct 7, 2021 · 0 comments
Open

How to get the current shard for a table #271

jacebenson opened this issue Oct 7, 2021 · 0 comments

Comments

@jacebenson
Copy link
Owner

// The following script (or variant thereof) can be used in 
// /sys.scripts.do or in a server-side script to determine
// the current shard for a table. 

printCurrentShard('sysevent'); 

function printCurrentShard(pTableName) { 
  var gr = new GlideRecord('sys_table_rotation'); 
  if (pTableName) { 
    gr.addQuery('name', '=', pTableName); 
  } 
  gr.query(); 
  while (gr.next()) { 
    try { 
      var tre =
Packages.com.snc.db.replicate.TableRotationExtensions.get();

      var extension = tre.getExtension(gr.name); 
      var tablename = extension.getTableName(); 
    } catch (e) { 
      gs.print('Error getting current shard for table ' + gr.name); 
    } finally { 
      gs.print('The current shard of table ' + gr.name + ' is ' + tablename); 
    } 
  } 
} 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant